-
Notifications
You must be signed in to change notification settings - Fork 10
/
Ling.tex
227 lines (178 loc) · 9.37 KB
/
Ling.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
\batchmode
%This Latex file is machine-generated by the BNF-converter
\documentclass[a4paper,11pt]{article}
\author{BNF-converter}
\title{The Language Ling}
\setlength{\parindent}{0mm}
\setlength{\parskip}{1mm}
\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 Ling}
\subsection*{Literals}
Integer literals \nonterminal{Int}\ are nonempty sequences of digits.
Name literals are recognized by the regular expression
\(({\nonterminal{letter}} \mid [\mbox{``\_{$-$}{$+$}*/'\%{\textasciicircum}''}] \mid {\nonterminal{digit}})* ({\nonterminal{letter}} \mid [\mbox{``\_{$-$}{$+$}*/'\%{\textasciicircum}''}]) ({\nonterminal{letter}} \mid [\mbox{``\_{$-$}{$+$}*/'\%{\textasciicircum}''}] \mid {\nonterminal{digit}})*\)
\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 Ling are the following: \\
\begin{tabular}{lll}
{\reserved{Fwd}} &{\reserved{Log}} &{\reserved{Sort}} \\
{\reserved{Type}} &{\reserved{as}} &{\reserved{end}} \\
{\reserved{fwd}} &{\reserved{new}} &{\reserved{proc}} \\
{\reserved{recv}} &{\reserved{send}} &{\reserved{slice}} \\
\end{tabular}\\
The symbols used in Ling are the following: \\
\begin{tabular}{lll}
{\symb{,}} &{\symb{{$=$}}} &{\symb{.}} \\
{\symb{:}} &{\symb{(}} &{\symb{)}} \\
{\symb{{$<$}}} &{\symb{{$>$}}} &{\symb{{$-$}{$>$}}} \\
{\symb{**}} &{\symb{{$|$}}} &{\symb{@}} \\
{\symb{\{}} &{\symb{\}}} &{\symb{[}} \\
{\symb{]}} &{\symb{[:}} &{\symb{:]}} \\
{\symb{!}} &{\symb{?}} &{\symb{\~{}}} \\
{\symb{{$-$}o}} &{\symb{{\textasciicircum}}} & \\
\end{tabular}\\
\subsection*{Comments}
Single-line comments begin with {\symb{{$-$}{$-$}}}. \\Multiple-line comments are enclosed with {\symb{\{{$-$}}} and {\symb{{$-$}\}}}.
\section*{The syntactic structure of Ling}
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{ListName}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Name}} \\
& {\delimit} &{\nonterminal{Name}} {\terminal{,}} {\nonterminal{ListName}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Program}} & {\arrow} &{\nonterminal{ListDec}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Dec}} & {\arrow} &{\nonterminal{Name}} {\nonterminal{OptChanDecs}} {\terminal{{$=$}}} {\nonterminal{Proc}} {\terminal{.}} \\
& {\delimit} &{\nonterminal{Name}} {\terminal{:}} {\nonterminal{Term}} {\terminal{.}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListDec}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Dec}} {\nonterminal{ListDec}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{VarDec}} & {\arrow} &{\terminal{(}} {\nonterminal{Name}} {\terminal{:}} {\nonterminal{Term}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListVarDec}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{VarDec}} {\nonterminal{ListVarDec}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{OptChanDecs}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\terminal{(}} {\nonterminal{ListChanDec}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ChanDec}} & {\arrow} &{\nonterminal{Name}} {\nonterminal{OptSession}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListChanDec}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{ChanDec}} \\
& {\delimit} &{\nonterminal{ChanDec}} {\terminal{,}} {\nonterminal{ListChanDec}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ATerm}} & {\arrow} &{\nonterminal{Name}} \\
& {\delimit} &{\nonterminal{Integer}} \\
& {\delimit} &{\terminal{Type}} \\
& {\delimit} &{\terminal{{$<$}}} {\nonterminal{ListRSession}} {\terminal{{$>$}}} \\
& {\delimit} &{\terminal{(}} {\nonterminal{Term}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListATerm}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{ATerm}} {\nonterminal{ListATerm}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{DTerm}} & {\arrow} &{\nonterminal{Name}} {\nonterminal{ListATerm}} \\
& {\delimit} &{\terminal{(}} {\nonterminal{Name}} {\terminal{:}} {\nonterminal{Term}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Term}} & {\arrow} &{\nonterminal{ATerm}} {\nonterminal{ListATerm}} \\
& {\delimit} &{\nonterminal{VarDec}} {\nonterminal{ListVarDec}} {\terminal{{$-$}{$>$}}} {\nonterminal{Term}} \\
& {\delimit} &{\nonterminal{VarDec}} {\nonterminal{ListVarDec}} {\terminal{**}} {\nonterminal{Term}} \\
& {\delimit} &{\terminal{proc}} {\terminal{(}} {\nonterminal{ListChanDec}} {\terminal{)}} {\nonterminal{Proc}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Proc}} & {\arrow} &{\nonterminal{ListPref}} {\nonterminal{Procs}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListProc}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Proc}} \\
& {\delimit} &{\nonterminal{Proc}} {\terminal{{$|$}}} {\nonterminal{ListProc}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Procs}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\terminal{fwd}} {\nonterminal{Session}} {\terminal{(}} {\nonterminal{ListName}} {\terminal{)}} \\
& {\delimit} &{\terminal{@}} {\nonterminal{ATerm}} {\terminal{(}} {\nonterminal{ListName}} {\terminal{)}} \\
& {\delimit} &{\terminal{slice}} {\terminal{(}} {\nonterminal{ListName}} {\terminal{)}} {\nonterminal{ATerm}} {\terminal{as}} {\nonterminal{Name}} {\nonterminal{Proc}} \\
& {\delimit} &{\terminal{(}} {\nonterminal{ListProc}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Pref}} & {\arrow} &{\terminal{new}} {\terminal{(}} {\nonterminal{ChanDec}} {\terminal{,}} {\nonterminal{ChanDec}} {\terminal{)}} \\
& {\delimit} &{\nonterminal{Name}} {\terminal{\{}} {\nonterminal{ListChanDec}} {\terminal{\}}} \\
& {\delimit} &{\nonterminal{Name}} {\terminal{[}} {\nonterminal{ListChanDec}} {\terminal{]}} \\
& {\delimit} &{\nonterminal{Name}} {\terminal{[:}} {\nonterminal{ListChanDec}} {\terminal{:]}} \\
& {\delimit} &{\terminal{send}} {\nonterminal{Name}} {\nonterminal{ATerm}} \\
& {\delimit} &{\terminal{recv}} {\nonterminal{Name}} {\nonterminal{VarDec}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListPref}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Pref}} {\nonterminal{ListPref}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{OptSession}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\terminal{:}} {\nonterminal{RSession}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Session4}} & {\arrow} &{\nonterminal{Name}} \\
& {\delimit} &{\terminal{end}} \\
& {\delimit} &{\terminal{\{}} {\nonterminal{ListRSession}} {\terminal{\}}} \\
& {\delimit} &{\terminal{[}} {\nonterminal{ListRSession}} {\terminal{]}} \\
& {\delimit} &{\terminal{[:}} {\nonterminal{ListRSession}} {\terminal{:]}} \\
& {\delimit} &{\terminal{(}} {\nonterminal{Session}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Session3}} & {\arrow} &{\terminal{Sort}} {\nonterminal{ATerm}} {\nonterminal{ATerm}} \\
& {\delimit} &{\terminal{Log}} {\nonterminal{Session4}} \\
& {\delimit} &{\terminal{Fwd}} {\nonterminal{Integer}} {\nonterminal{Session4}} \\
& {\delimit} &{\nonterminal{Session4}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Session2}} & {\arrow} &{\terminal{!}} {\nonterminal{DTerm}} {\nonterminal{CSession}} \\
& {\delimit} &{\terminal{?}} {\nonterminal{DTerm}} {\nonterminal{CSession}} \\
& {\delimit} &{\terminal{\~{}}} {\nonterminal{Session2}} \\
& {\delimit} &{\nonterminal{Session3}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Session}} & {\arrow} &{\nonterminal{Session2}} {\terminal{{$-$}o}} {\nonterminal{Session}} \\
& {\delimit} &{\nonterminal{Session2}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{RSession}} & {\arrow} &{\nonterminal{Session}} {\nonterminal{OptRepl}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListRSession}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{RSession}} \\
& {\delimit} &{\nonterminal{RSession}} {\terminal{,}} {\nonterminal{ListRSession}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{OptRepl}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\terminal{{\textasciicircum}}} {\nonterminal{ATerm}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{CSession}} & {\arrow} &{\terminal{.}} {\nonterminal{Session2}} \\
& {\delimit} &{\emptyP} \\
\end{tabular}\\
\end{document}