Add latex file

This commit is contained in:
Martin Fredin 2023-04-03 12:04:52 +02:00
parent 03bb6a8534
commit a1b1343d67
2 changed files with 222 additions and 12 deletions

215
Grammar.tex Normal file
View file

@ -0,0 +1,215 @@
%% File generated by the BNF Converter (bnfc 2.9.4.1).
\batchmode
\documentclass[a4paper,11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\setlength{\parindent}{0mm}
\setlength{\parskip}{1mm}
\title{The Language Grammar}
\author{BNF-converter}
\begin{document}
\maketitle
\newcommand{\emptyP}{\mbox{$\epsilon$}}
\newcommand{\terminal}[1]{\mbox{{\texttt {#1}}}}
\newcommand{\nonterminal}[1]{\mbox{$\langle \mbox{{\sl #1 }} \! \rangle$}}
\newcommand{\arrow}{\mbox{::=}}
\newcommand{\delimit}{\mbox{$|$}}
\newcommand{\reserved}[1]{\mbox{{\texttt {#1}}}}
\newcommand{\literal}[1]{\mbox{{\texttt {#1}}}}
\newcommand{\symb}[1]{\mbox{{\texttt {#1}}}}
This document was automatically generated by the {\em BNF-Converter}.
It was generated together with the lexer, the parser, and the
abstract syntax module, which guarantees that the document
matches with the implementation of the language
(provided no hand-hacking has taken place).
\section*{The lexical structure of Grammar}
\subsection*{Literals}
Character literals \nonterminal{Char}\ have the form
\terminal{'}$c$\terminal{'}, where $c$ is any single character.
Integer literals \nonterminal{Int}\ are nonempty sequences of digits.
UIdent literals are recognized by the regular expression
\({\nonterminal{upper}} (\mbox{`\_'} \mid {\nonterminal{digit}} \mid {\nonterminal{letter}})*\)
LIdent literals are recognized by the regular expression
\({\nonterminal{lower}} (\mbox{`\_'} \mid {\nonterminal{digit}} \mid {\nonterminal{letter}})*\)
\subsection*{Reserved words and symbols}
The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions.
The reserved words used in Grammar are the following: \\
\begin{tabular}{lll}
{\reserved{case}} &{\reserved{data}} &{\reserved{forall}} \\
{\reserved{in}} &{\reserved{let}} &{\reserved{of}} \\
{\reserved{where}} & & \\
\end{tabular}\\
The symbols used in Grammar are the following: \\
\begin{tabular}{lll}
{\symb{:}} &{\symb{{$=$}}} &{\symb{(}} \\
{\symb{)}} &{\symb{{$-$}{$>$}}} &{\symb{.}} \\
{\symb{\{}} &{\symb{\}}} &{\symb{{$+$}}} \\
{\symb{$\backslash$}} &{\symb{{$=$}{$>$}}} &{\symb{\_}} \\
{\symb{;}} & & \\
\end{tabular}\\
\subsection*{Comments}
Single-line comments begin with {\symb{{$-$}{$-$}}}. \\Multiple-line comments are enclosed with {\symb{\{{$-$}}} and {\symb{{$-$}\}}}.
\section*{The syntactic structure of Grammar}
Non-terminals are enclosed between $\langle$ and $\rangle$.
The symbols {\arrow} (production), {\delimit} (union)
and {\emptyP} (empty rule) belong to the BNF notation.
All other symbols are terminals.\\
\begin{tabular}{lll}
{\nonterminal{Program}} & {\arrow} &{\nonterminal{ListDef}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Def}} & {\arrow} &{\nonterminal{Bind}} \\
& {\delimit} &{\nonterminal{Sig}} \\
& {\delimit} &{\nonterminal{Data}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Sig}} & {\arrow} &{\nonterminal{LIdent}} {\terminal{:}} {\nonterminal{Type}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Bind}} & {\arrow} &{\nonterminal{LIdent}} {\nonterminal{ListLIdent}} {\terminal{{$=$}}} {\nonterminal{Exp}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Type1}} & {\arrow} &{\nonterminal{UIdent}} \\
& {\delimit} &{\nonterminal{TVar}} \\
& {\delimit} &{\nonterminal{UIdent}} {\terminal{(}} {\nonterminal{ListType}} {\terminal{)}} \\
& {\delimit} &{\terminal{(}} {\nonterminal{Type}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Type}} & {\arrow} &{\nonterminal{Type1}} {\terminal{{$-$}{$>$}}} {\nonterminal{Type}} \\
& {\delimit} &{\terminal{forall}} {\nonterminal{TVar}} {\terminal{.}} {\nonterminal{Type}} \\
& {\delimit} &{\nonterminal{Type1}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{TVar}} & {\arrow} &{\nonterminal{LIdent}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Data}} & {\arrow} &{\terminal{data}} {\nonterminal{Type}} {\terminal{where}} {\terminal{\{}} {\nonterminal{ListInj}} {\terminal{\}}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Inj}} & {\arrow} &{\nonterminal{UIdent}} {\terminal{:}} {\nonterminal{Type}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp4}} & {\arrow} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{:}} {\nonterminal{Type}} {\terminal{)}} \\
& {\delimit} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp3}} & {\arrow} &{\nonterminal{LIdent}} \\
& {\delimit} &{\nonterminal{UIdent}} \\
& {\delimit} &{\nonterminal{Lit}} \\
& {\delimit} &{\nonterminal{Exp4}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp2}} & {\arrow} &{\nonterminal{Exp2}} {\nonterminal{Exp3}} \\
& {\delimit} &{\nonterminal{Exp3}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp1}} & {\arrow} &{\nonterminal{Exp1}} {\terminal{{$+$}}} {\nonterminal{Exp2}} \\
& {\delimit} &{\nonterminal{Exp2}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp}} & {\arrow} &{\terminal{let}} {\nonterminal{Bind}} {\terminal{in}} {\nonterminal{Exp}} \\
& {\delimit} &{\terminal{$\backslash$}} {\nonterminal{LIdent}} {\terminal{.}} {\nonterminal{Exp}} \\
& {\delimit} &{\terminal{case}} {\nonterminal{Exp}} {\terminal{of}} {\terminal{\{}} {\nonterminal{ListBranch}} {\terminal{\}}} \\
& {\delimit} &{\nonterminal{Exp1}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Lit}} & {\arrow} &{\nonterminal{Integer}} \\
& {\delimit} &{\nonterminal{Char}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Branch}} & {\arrow} &{\nonterminal{Pattern}} {\terminal{{$=$}{$>$}}} {\nonterminal{Exp}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Pattern1}} & {\arrow} &{\nonterminal{LIdent}} \\
& {\delimit} &{\nonterminal{Lit}} \\
& {\delimit} &{\terminal{\_}} \\
& {\delimit} &{\nonterminal{UIdent}} \\
& {\delimit} &{\terminal{(}} {\nonterminal{Pattern}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Pattern}} & {\arrow} &{\nonterminal{UIdent}} {\nonterminal{ListPattern1}} \\
& {\delimit} &{\nonterminal{Pattern1}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListDef}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Def}} \\
& {\delimit} &{\nonterminal{Def}} {\terminal{;}} {\nonterminal{ListDef}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListBranch}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Branch}} \\
& {\delimit} &{\nonterminal{Branch}} {\terminal{;}} {\nonterminal{ListBranch}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListInj}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Inj}} \\
& {\delimit} &{\nonterminal{Inj}} {\terminal{;}} {\nonterminal{ListInj}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListLIdent}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{LIdent}} {\nonterminal{ListLIdent}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListType}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Type}} {\nonterminal{ListType}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListTVar}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{TVar}} {\nonterminal{ListTVar}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListPattern1}} & {\arrow} &{\nonterminal{Pattern1}} \\
& {\delimit} &{\nonterminal{Pattern1}} {\nonterminal{ListPattern1}} \\
\end{tabular}\\
\end{document}

View file

@ -1,6 +1,6 @@
.PHONY : sdist clean
language : src/Grammar/Test
language : src/Grammar/Test Grammar.tex
cabal install --installdir=. --overwrite-policy=always
src/Grammar/Test.hs src/Grammar/Lex.x src/Grammar/Par.y src/Grammar/Layout : Grammar.cf
@ -18,21 +18,16 @@ src/Grammar/%.y : Grammar.cf
src/Grammar/Test : src/Grammar/Test.hs src/Grammar/Par.hs src/Grammar/Lex.hs src/Grammar/Layout
ghc src/Grammar/Test.hs src/Grammar/Par.hs src/Grammar/Lex.hs src/Grammar/Abs.hs src/Grammar/Skel.hs src/Grammar/Print.hs src/Grammar/Layout -o src/Grammar/test
Grammar.tex :
bnfc --latex Grammar.cf
clean :
rm -r src/Grammar
rm language
rm -rf dist-newstyles
rm Grammar.aux Grammar.fdb_latexmk Grammar.fls Grammar.log Grammar.pdf Grammar.synctex.gz Grammar.tex
test :
./language ./sample-programs/basic-1
./language ./sample-programs/basic-2
./language ./sample-programs/basic-3
./language ./sample-programs/basic-4
./language ./sample-programs/basic-5
./language ./sample-programs/basic-6
./language ./sample-programs/basic-7
./language ./sample-programs/basic-8
run :
cabal -v0 new-run language -- "test_program"
cabal v2-test
# EOF