-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjakub_kuszneruk.tex
243 lines (195 loc) · 9.02 KB
/
jakub_kuszneruk.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
\batchmode
%This Latex file is machine-generated by the BNF-converter
\documentclass[a4paper,11pt]{article}
\author{BNF-converter}
\title{The Language shl}
\setlength{\parindent}{0mm}
\setlength{\parskip}{1mm}
%pl
\usepackage[T1]{fontenc}
\usepackage[polish]{babel}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\selectlanguage{polish}
\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}}}}
\newcommand{\tb}{\hspace{5mm}}
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 shl}
\subsection*{Identifiers}
Identifiers \nonterminal{Ident} are unquoted strings beginning with a letter,
followed by any combination of letters, digits, and the characters {\tt \_ '},
reserved words excluded.
\subsection*{Literals}
Integer literals \nonterminal{Int}\ are nonempty sequences of digits.
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.
\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 shl are the following: \\
\begin{tabular}{lll}
{\reserved{Boolean}} &{\reserved{CYA}} &{\reserved{DO}} \\
{\reserved{DONE}} &{\reserved{ELSE}} &{\reserved{FI}} \\
{\reserved{FOR}} &{\reserved{False}} &{\reserved{IF}} \\
{\reserved{IN}} &{\reserved{Integer}} &{\reserved{PRINT}} \\
{\reserved{REF}} &{\reserved{RETURN}} &{\reserved{RETURNED}} \\
{\reserved{SOLUTION}} &{\reserved{String}} &{\reserved{THEN}} \\
{\reserved{True}} & & \\
\end{tabular}\\
The symbols used in shl 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}\\
\subsection*{Comments}
Single-line comments begin with {\symb{{$<$}{$=$}{$=$}3}}. \\Multiple-line comments are enclosed with {\symb{{$<$}{$=$}}} and {\symb{{$=$}3}}.
\section*{The syntactic structure of shl}
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{Prog}} & {\arrow} &{\terminal{SOLUTION}} {\nonterminal{Blk}} {\terminal{CYA}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Blk}} & {\arrow} &{\nonterminal{ListDec}} {\nonterminal{ListStm}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Stm}} & {\arrow} &{\terminal{FOR}} {\nonterminal{Ident}} {\terminal{IN}} {\nonterminal{Exp}} {\terminal{DO}} {\nonterminal{Blk}} {\terminal{DONE}} \\
& {\delimit} &{\terminal{IF}} {\nonterminal{Exp}} {\terminal{THEN}} {\nonterminal{Blk}} {\terminal{FI}} \\
& {\delimit} &{\terminal{IF}} {\nonterminal{Exp}} {\terminal{THEN}} {\nonterminal{Blk}} {\terminal{ELSE}} {\nonterminal{Blk}} {\terminal{FI}} \\
& {\delimit} &{\terminal{RETURN}} {\nonterminal{Exp}} {\terminal{;}} \\
& {\delimit} &{\terminal{PRINT}} {\nonterminal{Exp}} {\terminal{;}} \\
& {\delimit} &{\nonterminal{Exp}} {\terminal{;}} \\
& {\delimit} &{\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}} {\terminal{;}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListStm}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Stm}} {\nonterminal{ListStm}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Dec}} & {\arrow} &{\nonterminal{Typ}} {\nonterminal{Ident}} {\terminal{;}} \\
& {\delimit} &{\nonterminal{Typ}} {\nonterminal{Ident}} {\terminal{{$=$}}} {\nonterminal{Exp}} {\terminal{;}} \\
& {\delimit} &{\nonterminal{Typ}} {\nonterminal{Ident}} {\terminal{(}} {\nonterminal{ListFArg}} {\terminal{)}} {\terminal{DO}} {\nonterminal{Blk}} {\terminal{RETURNED}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{FArg}} & {\arrow} &{\nonterminal{Typ}} {\nonterminal{Ident}} \\
& {\delimit} &{\terminal{REF}} {\nonterminal{Typ}} {\nonterminal{Ident}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListFArg}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{FArg}} \\
& {\delimit} &{\nonterminal{FArg}} {\terminal{,}} {\nonterminal{ListFArg}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListDec}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{Dec}} {\nonterminal{ListDec}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Typ}} & {\arrow} &{\terminal{Integer}} \\
& {\delimit} &{\terminal{Boolean}} \\
& {\delimit} &{\terminal{String}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp}} & {\arrow} &{\nonterminal{Exp}} {\terminal{{$=$}{$=$}}} {\nonterminal{Exp2}} \\
& {\delimit} &{\nonterminal{Exp}} {\terminal{!{$=$}}} {\nonterminal{Exp2}} \\
& {\delimit} &{\nonterminal{Exp1}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp2}} & {\arrow} &{\nonterminal{Exp2}} {\terminal{{$<$}}} {\nonterminal{Exp3}} \\
& {\delimit} &{\nonterminal{Exp2}} {\terminal{{$>$}}} {\nonterminal{Exp3}} \\
& {\delimit} &{\nonterminal{Exp2}} {\terminal{{$<$}{$=$}}} {\nonterminal{Exp3}} \\
& {\delimit} &{\nonterminal{Exp2}} {\terminal{{$>$}{$=$}}} {\nonterminal{Exp3}} \\
& {\delimit} &{\nonterminal{Exp3}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp3}} & {\arrow} &{\nonterminal{Exp3}} {\terminal{{$+$}}} {\nonterminal{Exp4}} \\
& {\delimit} &{\nonterminal{Exp3}} {\terminal{{$-$}}} {\nonterminal{Exp4}} \\
& {\delimit} &{\nonterminal{Exp4}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp4}} & {\arrow} &{\nonterminal{Exp4}} {\terminal{*}} {\nonterminal{Exp5}} \\
& {\delimit} &{\nonterminal{Exp4}} {\terminal{/}} {\nonterminal{Exp5}} \\
& {\delimit} &{\nonterminal{Exp5}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp5}} & {\arrow} &{\nonterminal{Ident}} {\terminal{{$+$}{$+$}}} \\
& {\delimit} &{\nonterminal{Ident}} {\terminal{{$-$}{$-$}}} \\
& {\delimit} &{\nonterminal{Ident}} {\terminal{(}} {\nonterminal{ListIParam}} {\terminal{)}} \\
& {\delimit} &{\nonterminal{Ident}} \\
& {\delimit} &{\nonterminal{Constraint}} \\
& {\delimit} &{\nonterminal{Exp6}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp1}} & {\arrow} &{\nonterminal{Exp2}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Exp6}} & {\arrow} &{\terminal{(}} {\nonterminal{Exp}} {\terminal{)}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{Constraint}} & {\arrow} &{\nonterminal{Integer}} \\
& {\delimit} &{\nonterminal{BoolT}} \\
& {\delimit} &{\nonterminal{String}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{BoolT}} & {\arrow} &{\terminal{True}} \\
& {\delimit} &{\terminal{False}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{IParam}} & {\arrow} &{\nonterminal{Exp}} \\
\end{tabular}\\
\begin{tabular}{lll}
{\nonterminal{ListIParam}} & {\arrow} &{\emptyP} \\
& {\delimit} &{\nonterminal{IParam}} \\
& {\delimit} &{\nonterminal{IParam}} {\terminal{,}} {\nonterminal{ListIParam}} \\
\end{tabular}\\
\clearpage
\begin{tabular}{lll}
SOLUTION \\
\tb Integer increase (Integer a) \\
\tb DO \\
\tb \tb a++; \\
\tb \tb RETURN a \\
\tb RETURNED \\
\tb Integer increaseR (REF Integer a) \\
\tb DO \\
\tb \tb a++; \\
\tb RETURNED \\
\tb Integer a = 41 - 42; \\
\tb Integer counter0 = 0; \\
\tb FOR i IN 3 \\
\tb DO \\
\tb IF a \\
\tb \tb a = increase(a); \\
\tb ELSE \\
\tb \tb increaseR(counter0); \\
\tb FI \\
\tb DONE \\
\tb $<$= After evaluation counter0 equals to 1 =3 \\
\tb PRINT counter0 \\
CYA \\
\end{tabular}\\
Język składnią bardzo przypomina PASCALA.\\
Wszystkie konstrukcje powinny być zrozumiałe:
\begin{itemize}
\item wyrażenia na zmiennych są zapożyczone z C++
\item typy danych nazywają się podobnie jak w innych językach
\item bloki podobnie jak w bashu ujęte są w znaczniki DO DONE, z wyjątkiem funkcji, które konczą się znacznikiem RETURNED\\
\item przyjmowanie wartości przez referencję oznaczaone jest przez REF poprzedzający nazwę typu
\item cały program ujety jest w znaczniki SOLUTION I CYA
\item mnogość wyrażeń (Exp1..6) spowodowana jest kolejnością ich ewaluacji
\end{itemize}
\end{document}