]> ruin.nu Git - proglang.git/blob - Docsyntax.tex
b22e5448befef0133379770c9d9808a2e2ed5178
[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{true}} \\
46 {\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 \end{tabular}\\
59
60 \subsection*{Comments}
61 Single-line comments begin with {\symb{//}}. \\Multiple-line comments are  enclosed with {\symb{/*}} and {\symb{*/}}.
62
63 \section*{The syntactic structure of syntax}
64 Non-terminals are enclosed between $\langle$ and $\rangle$. 
65 The symbols  {\arrow}  (production),  {\delimit}  (union) 
66 and {\emptyP} (empty rule) belong to the BNF notation. 
67 All other symbols are terminals.\\
68
69 \begin{tabular}{lll}
70 {\nonterminal{Bool}} & {\arrow}  &{\terminal{true}}  \\
71  & {\delimit}  &{\terminal{false}}  \\
72 \end{tabular}\\
73
74 \begin{tabular}{lll}
75 {\nonterminal{Stm}} & {\arrow}  &{\nonterminal{Type}} {\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}} {\terminal{;}}  \\
76  & {\delimit}  &{\nonterminal{Type}} {\nonterminal{Ident}} {\terminal{;}}  \\
77  & {\delimit}  &{\nonterminal{Exp}} {\terminal{;}}  \\
78  & {\delimit}  &{\terminal{\{}} {\nonterminal{ListStm}} {\terminal{\}}}  \\
79  & {\delimit}  &{\terminal{if}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}}  \\
80  & {\delimit}  &{\terminal{if}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}} {\terminal{else}} {\nonterminal{Stm}}  \\
81  & {\delimit}  &{\terminal{while}} {\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} {\nonterminal{Stm}}  \\
82  & {\delimit}  &{\terminal{print}} {\nonterminal{Exp}} {\terminal{;}}  \\
83  & {\delimit}  &{\nonterminal{Stm}} {\terminal{;}}  \\
84 \end{tabular}\\
85
86 \begin{tabular}{lll}
87 {\nonterminal{Exp}} & {\arrow}  &{\nonterminal{Exp1}} {\nonterminal{BOp}} {\nonterminal{Exp1}}  \\
88  & {\delimit}  &{\nonterminal{Exp1}}  \\
89 \end{tabular}\\
90
91 \begin{tabular}{lll}
92 {\nonterminal{Exp1}} & {\arrow}  &{\nonterminal{Exp1}} {\nonterminal{Op1}} {\nonterminal{Exp2}}  \\
93  & {\delimit}  &{\nonterminal{Exp2}}  \\
94 \end{tabular}\\
95
96 \begin{tabular}{lll}
97 {\nonterminal{Exp2}} & {\arrow}  &{\nonterminal{Exp2}} {\nonterminal{Op2}} {\nonterminal{Exp3}}  \\
98  & {\delimit}  &{\nonterminal{Exp3}}  \\
99 \end{tabular}\\
100
101 \begin{tabular}{lll}
102 {\nonterminal{Exp3}} & {\arrow}  &{\nonterminal{Ident}} {\terminal{{$+$}{$+$}}}  \\
103  & {\delimit}  &{\nonterminal{Ident}} {\terminal{{$-$}{$-$}}}  \\
104  & {\delimit}  &{\nonterminal{Ident}}  \\
105  & {\delimit}  &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}}  \\
106  & {\delimit}  &{\nonterminal{Integer}}  \\
107  & {\delimit}  &{\terminal{{$-$}}} {\nonterminal{Exp3}}  \\
108  & {\delimit}  &{\nonterminal{Bool}}  \\
109  & {\delimit}  &{\terminal{readInt}}  \\
110  & {\delimit}  &{\terminal{readBool}}  \\
111  & {\delimit}  &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}}  \\
112 \end{tabular}\\
113
114 \begin{tabular}{lll}
115 {\nonterminal{ListStm}} & {\arrow}  &{\emptyP} \\
116  & {\delimit}  &{\nonterminal{Stm}} {\nonterminal{ListStm}}  \\
117 \end{tabular}\\
118
119 \begin{tabular}{lll}
120 {\nonterminal{Stms}} & {\arrow}  &{\nonterminal{ListStm}}  \\
121 \end{tabular}\\
122
123 \begin{tabular}{lll}
124 {\nonterminal{BOp}} & {\arrow}  &{\terminal{{$<$}}}  \\
125  & {\delimit}  &{\terminal{{$<$}{$=$}}}  \\
126  & {\delimit}  &{\terminal{{$>$}}}  \\
127  & {\delimit}  &{\terminal{{$>$}{$=$}}}  \\
128  & {\delimit}  &{\terminal{{$=$}{$=$}}}  \\
129  & {\delimit}  &{\terminal{!{$=$}}}  \\
130 \end{tabular}\\
131
132 \begin{tabular}{lll}
133 {\nonterminal{Op1}} & {\arrow}  &{\terminal{{$+$}}}  \\
134  & {\delimit}  &{\terminal{{$-$}}}  \\
135 \end{tabular}\\
136
137 \begin{tabular}{lll}
138 {\nonterminal{Op2}} & {\arrow}  &{\terminal{*}}  \\
139  & {\delimit}  &{\terminal{/}}  \\
140 \end{tabular}\\
141
142 \begin{tabular}{lll}
143 {\nonterminal{Op}} & {\arrow}  &{\nonterminal{Op1}}  \\
144  & {\delimit}  &{\nonterminal{Op2}}  \\
145 \end{tabular}\\
146
147 \begin{tabular}{lll}
148 {\nonterminal{Type}} & {\arrow}  &{\terminal{int}}  \\
149  & {\delimit}  &{\terminal{bool}}  \\
150 \end{tabular}\\
151
152
153
154 \end{document}
155