-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrammar.txt
37 lines (25 loc) · 1.39 KB
/
grammar.txt
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
(* [] - Optional, (0 or 1 times) *)
(* {} - Repeat, 0 or more times *)
(* () - Grouping *)
(* , - Concatenation *)
(* ; - Termination *)
(* | - Alternation *)
(* = - Definition *)
statement = ( assignment | function_application ), ";" ;
assignment = type_expresion, ":=", identifier ;
type_expresion = basic_type, ": ", expresion ;
expresion = function_application | identifier | number | string_literal ;
(* Open bracket, with zero or one expresion as the argument, or a expresion followed by zero or more 'comma expresion' (list of arguments) *)
function_application = "(", ( [expresion] | ( expresion, { ",", expresion } ) ), ")", ( identifier | built_in_function ) ;
identifier = letter, { letter } ;
basic_type = "int" | "bool" | "string" | "char" | "real" ;
built_in_function = "print" ;
number = [ "-" ], digit, { digit } ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
string_literal = """, ? Any ASCII character ?, """ '
letter = upper_letter | lower_letter ;
upper_letters = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" |
"N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" ;
lower_letters = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" |
"n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" ;
white_space = ? white space characters ? ;