]> ruin.nu Git - proglang.git/blob - Docsyntax.tex
minor change
[proglang.git] / Docsyntax.tex
1 \batchmode
2 %This Latex file is machine-generated by the BNF-converter
3
4 \documentclass[a4paper,11pt]{article}
5 \author{BNF-converter}
6 \title{The Language syntax}
7 \setlength{\parindent}{0mm}
8 \setlength{\parskip}{1mm}
9 \begin{document}
10
11 \maketitle
12
13 \newcommand{\emptyP}{\mbox{$\epsilon$}}
14 \newcommand{\terminal}[1]{\mbox{{\texttt {#1}}}}
15 \newcommand{\nonterminal}[1]{\mbox{$\langle \mbox{{\sl #1 }} \! \rangle$}}
16 \newcommand{\arrow}{\mbox{::=}}
17 \newcommand{\delimit}{\mbox{$|$}}
18 \newcommand{\reserved}[1]{\mbox{{\texttt {#1}}}}
19 \newcommand{\literal}[1]{\mbox{{\texttt {#1}}}}
20 \newcommand{\symb}[1]{\mbox{{\texttt {#1}}}}
21
22 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).
23
24 \section*{The lexical structure of syntax}
25 \subsection*{Identifiers}
26 Identifiers \nonterminal{Ident} are unquoted strings beginning with a letter,
27 followed by any combination of letters, digits, and the characters {\tt \_ '},
28 reserved words excluded.
29
30
31 \subsection*{Literals}
32 Integer literals \nonterminal{Int}\ are nonempty sequences of digits.
33
34
35
36
37 \subsection*{Reserved words and symbols}
38 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.
39
40 The reserved words used in syntax are the following: \\
41
42 \begin{tabular}{lll}
43 {\reserved{bool}} &{\reserved{else}} &{\reserved{false}} \\
44 {\reserved{if}} &{\reserved{int}} &{\reserved{print}} \\
45 {\reserved{readBool}} &{\reserved{readInt}} &{\reserved{return}} \\
46 {\reserved{true}} &{\reserved{while}} & \\
47 \end{tabular}\\
48
49 The symbols used in syntax are the following: \\
50
51 \begin{tabular}{lll}
52 {\symb{;}} &{\symb{\{}} &{\symb{\}}} \\
53 {\symb{{$=$}}} &{\symb{(}} &{\symb{)}} \\
54 {\symb{{$+$}{$+$}}} &{\symb{{$-$}{$-$}}} &{\symb{{$-$}}} \\
55 {\symb{!}} &{\symb{,}} &{\symb{{$<$}}} \\
56 {\symb{{$<$}{$=$}}} &{\symb{{$>$}}} &{\symb{{$>$}{$=$}}} \\
57 {\symb{{$=$}{$=$}}} &{\symb{!{$=$}}} &{\symb{{$+$}}} \\
58 {\symb{*}} &{\symb{/}} & \\
59 \end{tabular}\\
60
61 \subsection*{Comments}
62 Single-line comments begin with {\symb{//}}. \\Multiple-line comments are  enclosed with {\symb{/*}} and {\symb{*/}}.
63
64 \section*{The syntactic structure of syntax}
65 Non-terminals are enclosed between $\langle$ and $\rangle$. 
66 The symbols  {\arrow}  (production),  {\delimit}  (union) 
67 and {\emptyP} (empty rule) belong to the BNF notation. 
68 All other symbols are terminals.\\
69
70 \begin{tabular}{lll}
71 {\nonterminal{Bool}} & {\arrow}  &{\terminal{true}}  \\
72  & {\delimit}  &{\terminal{false}}  \\
73 \end{tabular}\\
74
75 \begin{tabular}{lll}
76 {\nonterminal{Type}} & {\arrow}  &{\terminal{int}}  \\
77  & {\delimit}  &{\terminal{bool}}  \\
78 \end{tabular}\\
79
80 \begin{tabular}{lll}
81 {\nonterminal{Program}} & {\arrow}  &{\nonterminal{ListFuncStm}}  \\
82 \end{tabular}\\
83
84 \begin{tabular}{lll}
85 {\nonterminal{Stm}} & {\arrow}  &{\nonterminal{Exp}} {\terminal{;}}  \\
86  & {\delimit}  &{\terminal{\{}} {\nonterminal{ListStm}} {\terminal{\}}}  \\
87  & {\delimit}  &{\nonterminal{Type}} {\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}} {\terminal{;}}  \\
88  & {\delimit}  &{\nonterminal{Type}} {\nonterminal{Ident}} {\terminal{;}}  \\
89  & {\delimit}  &{\terminal{while}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}}  \\
90  & {\delimit}  &{\terminal{if}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}} {\terminal{else}} {\nonterminal{Stm}}  \\
91  & {\delimit}  &{\terminal{if}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}}  \\
92  & {\delimit}  &{\terminal{print}} {\nonterminal{Exp}} {\terminal{;}}  \\
93  & {\delimit}  &{\terminal{return}} {\nonterminal{Exp}} {\terminal{;}}  \\
94 \end{tabular}\\
95
96 \begin{tabular}{lll}
97 {\nonterminal{Exp}} & {\arrow}  &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}}  \\
98  & {\delimit}  &{\nonterminal{Exp1}} {\nonterminal{Op0}} {\nonterminal{Exp1}}  \\
99  & {\delimit}  &{\nonterminal{Exp1}}  \\
100 \end{tabular}\\
101
102 \begin{tabular}{lll}
103 {\nonterminal{Exp1}} & {\arrow}  &{\nonterminal{Exp1}} {\nonterminal{Op1}} {\nonterminal{Exp2}}  \\
104  & {\delimit}  &{\nonterminal{Exp2}}  \\
105 \end{tabular}\\
106
107 \begin{tabular}{lll}
108 {\nonterminal{Exp2}} & {\arrow}  &{\nonterminal{Exp2}} {\nonterminal{Op2}} {\nonterminal{Exp3}}  \\
109  & {\delimit}  &{\nonterminal{Exp3}}  \\
110 \end{tabular}\\
111
112 \begin{tabular}{lll}
113 {\nonterminal{Exp3}} & {\arrow}  &{\nonterminal{Ident}} {\terminal{{$+$}{$+$}}}  \\
114  & {\delimit}  &{\nonterminal{Ident}} {\terminal{{$-$}{$-$}}}  \\
115  & {\delimit}  &{\nonterminal{Ident}}  \\
116  & {\delimit}  &{\nonterminal{Integer}}  \\
117  & {\delimit}  &{\nonterminal{Bool}}  \\
118  & {\delimit}  &{\terminal{{$-$}}} {\nonterminal{Exp3}}  \\
119  & {\delimit}  &{\terminal{!}} {\nonterminal{Exp3}}  \\
120  & {\delimit}  &{\terminal{readInt}}  \\
121  & {\delimit}  &{\terminal{readBool}}  \\
122  & {\delimit}  &{\nonterminal{Ident}} {\terminal{(}} {\nonterminal{ListExp}} {\terminal{)}}  \\
123  & {\delimit}  &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}}  \\
124 \end{tabular}\\
125
126 \begin{tabular}{lll}
127 {\nonterminal{ListStm}} & {\arrow}  &{\emptyP} \\
128  & {\delimit}  &{\nonterminal{Stm}} {\nonterminal{ListStm}}  \\
129 \end{tabular}\\
130
131 \begin{tabular}{lll}
132 {\nonterminal{ListExp}} & {\arrow}  &{\emptyP} \\
133  & {\delimit}  &{\nonterminal{Exp}}  \\
134  & {\delimit}  &{\nonterminal{Exp}} {\terminal{,}} {\nonterminal{ListExp}}  \\
135 \end{tabular}\\
136
137 \begin{tabular}{lll}
138 {\nonterminal{Decl}} & {\arrow}  &{\nonterminal{Type}} {\nonterminal{Ident}}  \\
139 \end{tabular}\\
140
141 \begin{tabular}{lll}
142 {\nonterminal{ListDecl}} & {\arrow}  &{\emptyP} \\
143  & {\delimit}  &{\nonterminal{Decl}}  \\
144  & {\delimit}  &{\nonterminal{Decl}} {\terminal{,}} {\nonterminal{ListDecl}}  \\
145 \end{tabular}\\
146
147 \begin{tabular}{lll}
148 {\nonterminal{Func}} & {\arrow}  &{\nonterminal{Type}} {\nonterminal{Ident}} {\terminal{(}} {\nonterminal{ListDecl}} {\terminal{)}} {\terminal{\{}} {\nonterminal{ListStm}} {\terminal{\}}}  \\
149 \end{tabular}\\
150
151 \begin{tabular}{lll}
152 {\nonterminal{ListFunc}} & {\arrow}  &{\emptyP} \\
153  & {\delimit}  &{\nonterminal{Func}} {\nonterminal{ListFunc}}  \\
154 \end{tabular}\\
155
156 \begin{tabular}{lll}
157 {\nonterminal{FuncStm}} & {\arrow}  &{\nonterminal{Stm}}  \\
158  & {\delimit}  &{\nonterminal{Func}}  \\
159 \end{tabular}\\
160
161 \begin{tabular}{lll}
162 {\nonterminal{ListFuncStm}} & {\arrow}  &{\emptyP} \\
163  & {\delimit}  &{\nonterminal{FuncStm}} {\nonterminal{ListFuncStm}}  \\
164 \end{tabular}\\
165
166 \begin{tabular}{lll}
167 {\nonterminal{Op0}} & {\arrow}  &{\terminal{{$<$}}}  \\
168  & {\delimit}  &{\terminal{{$<$}{$=$}}}  \\
169  & {\delimit}  &{\terminal{{$>$}}}  \\
170  & {\delimit}  &{\terminal{{$>$}{$=$}}}  \\
171  & {\delimit}  &{\terminal{{$=$}{$=$}}}  \\
172  & {\delimit}  &{\terminal{!{$=$}}}  \\
173 \end{tabular}\\
174
175 \begin{tabular}{lll}
176 {\nonterminal{Op1}} & {\arrow}  &{\terminal{{$+$}}}  \\
177  & {\delimit}  &{\terminal{{$-$}}}  \\
178 \end{tabular}\\
179
180 \begin{tabular}{lll}
181 {\nonterminal{Op2}} & {\arrow}  &{\terminal{*}}  \\
182  & {\delimit}  &{\terminal{/}}  \\
183 \end{tabular}\\
184
185 \begin{tabular}{lll}
186 {\nonterminal{Op}} & {\arrow}  &{\nonterminal{Op1}}  \\
187  & {\delimit}  &{\nonterminal{Op2}}  \\
188  & {\delimit}  &{\nonterminal{Op0}}  \\
189 \end{tabular}\\
190
191
192
193 \end{document}
194