-
Notifications
You must be signed in to change notification settings - Fork 165
/
lbnf_spec.tex
198 lines (155 loc) · 7.18 KB
/
lbnf_spec.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
\begin{figure}
\begin{minipage}[l]{0.4\textwidth}
\large
\begin{center}
\textbf{Appendix}
\ \\
\textbf{LBNF Specification}
\end{center}
\scriptsize
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).
\normalsize
\textbf{The lexical structure of LBNF}
\textbf{Identifiers}
\scriptsize
Identifiers \nonterminal{Ident} are unquoted strings beginning with a letter,
followed by any combination of letters, digits, and the characters {\tt \_ '},
reserved words excluded.
\normalsize
\textbf{Literals}
\scriptsize
String literals \nonterminal{String}\ have the form
\terminal{"}$x$\terminal{"}, where $x$ is any sequence of any characters
except \terminal{"}\ unless preceded by \verb6\6.
Integer literals \nonterminal{Int}\ are nonempty sequences of digits.
Character literals \nonterminal{Char}\ have the form
\terminal{'}$c$\terminal{'}, where $c$ is any single character.
\normalsize
\textbf{Reserved words and symbols}
\scriptsize
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 LBNF are the following: \\
\begin{tabular}{lll}
{\reserved{char}} &{\reserved{coercions}} &{\reserved{comment}} \\
{\reserved{digit}} &{\reserved{entrypoints}} &{\reserved{eps}} \\
{\reserved{internal}} &{\reserved{layout}} &{\reserved{letter}} \\
{\reserved{lower}} &{\reserved{nonempty}} &{\reserved{rules}} \\
{\reserved{separator}} &{\reserved{stop}} &{\reserved{terminator}} \\
{\reserved{token}} &{\reserved{toplevel}} &{\reserved{upper}} \\
\end{tabular}\\
The symbols used in LBNF are the following: \\
\begin{tabular}{lll}
{\symb{;}} &{\symb{.}} &{\symb{::{$=$}}} \\
{\symb{[}} &{\symb{]}} &{\symb{ \_ }} \\
{\symb{(}} &{\symb{:}} &{\symb{)}} \\
{\symb{,}} &{\symb{{$|$}}} &{\symb{{$-$}}} \\
{\symb{*}} &{\symb{{$+$}}} &{\symb{?}} \\
{\symb{\{}} &{\symb{\}}} & \\
\end{tabular}\\
\normalsize
\textbf{Comments}
\scriptsize
Single-line comments begin with {\symb{{$-$}{$-$}}}. \\Multiple-line comments are enclosed with {\symb{\{ {$-$}}} and {\symb{{$-$} \} }}.
\end{minipage}
\hfill
\begin{minipage}[r]{0.5\textwidth}
\textbf{The syntactic structure of LBNF}
\scriptsize
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{Grammar}} & {\arrow} &{\nonterminal{ListDef}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListDef}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Def}} {\terminal{;}} {\nonterminal{ListDef}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListItem}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Item}} {\nonterminal{ListItem}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Def}} & {\arrow} &{\nonterminal{Label}} {\terminal{.}} {\nonterminal{Cat}} {\terminal{::{$=$}}} {\nonterminal{ListItem}} \\
& {\delimit} &{\terminal{comment}} {\nonterminal{String}} \\
& {\delimit} &{\terminal{comment}} {\nonterminal{String}} {\nonterminal{String}} \\
& {\delimit} &{\terminal{internal}} {\nonterminal{Label}} {\terminal{.}} {\nonterminal{Cat}} {\terminal{::{$=$}}} {\nonterminal{ListItem}} \\
& {\delimit} &{\terminal{token}} {\nonterminal{Ident}} {\nonterminal{Reg}} \\
& {\delimit} &{\terminal{entrypoints}} {\nonterminal{ListIdent}} \\
& {\delimit} &{\terminal{separator}} {\nonterminal{MinimumSize}} {\nonterminal{Cat}} {\nonterminal{String}} \\
& {\delimit} &{\terminal{terminator}} {\nonterminal{MinimumSize}} {\nonterminal{Cat}} {\nonterminal{String}} \\
& {\delimit} &{\terminal{coercions}} {\nonterminal{Ident}} {\nonterminal{Integer}} \\
& {\delimit} &{\terminal{rules}} {\nonterminal{Ident}} {\terminal{::{$=$}}} {\nonterminal{ListRHS}} \\
& {\delimit} &{\terminal{layout}} {\nonterminal{ListString}} \\
& {\delimit} &{\terminal{layout}} {\terminal{stop}} {\nonterminal{ListString}} \\
& {\delimit} &{\terminal{layout}} {\terminal{toplevel}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Item}} & {\arrow} &{\nonterminal{String}} \\
& {\delimit} &{\nonterminal{Cat}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Cat}} & {\arrow} &{\terminal{[}} {\nonterminal{Cat}} {\terminal{]}} \\
& {\delimit} &{\nonterminal{Ident}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Label}} & {\arrow} &{\nonterminal{Ident}} \\
& {\delimit} &{\terminal{ \_ }} \\
& {\delimit} &{\terminal{[}} {\terminal{]}} \\
& {\delimit} &{\terminal{(}} {\terminal{:}} {\terminal{)}} \\
& {\delimit} &{\terminal{(}} {\terminal{:}} {\terminal{[}} {\terminal{]}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListString}} & {\arrow} &{\nonterminal{String}} \\
& {\delimit} &{\nonterminal{String}} {\terminal{,}} {\nonterminal{ListString}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListRHS}} & {\arrow} &{\nonterminal{RHS}} \\
& {\delimit} &{\nonterminal{RHS}} {\terminal{{$|$}}} {\nonterminal{ListRHS}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{RHS}} & {\arrow} &{\nonterminal{ListItem}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{MinimumSize}} & {\arrow} &{\terminal{nonempty}} \\
& {\delimit} &{\emptyP} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Reg2}} & {\arrow} &{\nonterminal{Reg2}} {\nonterminal{Reg3}} \\
& {\delimit} &{\nonterminal{Reg3}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Reg1}} & {\arrow} &{\nonterminal{Reg1}} {\terminal{{$|$}}} {\nonterminal{Reg2}} \\
& {\delimit} &{\nonterminal{Reg2}} {\terminal{{$-$}}} {\nonterminal{Reg2}} \\
& {\delimit} &{\nonterminal{Reg2}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Reg3}} & {\arrow} &{\nonterminal{Reg3}} {\terminal{*}} \\
& {\delimit} &{\nonterminal{Reg3}} {\terminal{{$+$}}} \\
& {\delimit} &{\nonterminal{Reg3}} {\terminal{?}} \\
& {\delimit} &{\terminal{eps}} \\
& {\delimit} &{\nonterminal{Char}} \\
& {\delimit} &{\terminal{[}} {\nonterminal{String}} {\terminal{]}} \\
& {\delimit} &{\terminal{\{}} {\nonterminal{String}} {\terminal{\}}} \\
& {\delimit} &{\terminal{digit}} \\
& {\delimit} &{\terminal{letter}} \\
& {\delimit} &{\terminal{upper}} \\
& {\delimit} &{\terminal{lower}} \\
& {\delimit} &{\terminal{char}} \\
& {\delimit} &{\terminal{(}} {\nonterminal{Reg}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Reg}} & {\arrow} &{\nonterminal{Reg1}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListIdent}} & {\arrow} &{\nonterminal{Ident}} \\
& {\delimit} &{\nonterminal{Ident}} {\terminal{,}} {\nonterminal{ListIdent}} \\
\end{tabular}\\
\hfill
\end{minipage}
\label{fig:lbnf}
\end{figure}