-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grammar
37 lines (20 loc) · 1.36 KB
/
Grammar
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
program = "program" identifier ";" { var_declaration } { function_declaration } { var_declaration } expression "." ;
var_declaration = ( "var" | "const" ) ( identifier { "," identifier } ( ":" type | = expression ) ";" ) +;
function_declaration = "function" identifier "(" [ identifier ":" type { ";" identifier ":" type } ] ")" ":" type ";"
{ var_declaration }
expression ";" ;
expression = block | if | while | for | operationL6 | ;
block = "begin" expression { ";" expression } "end";
operationL0 = identifier | literal | identifier "(" [ call_args ] ")" | "(" expression ")" | identifier "[" expression "]" ;
operationL1 = operationL0 | "!" operationL1 | "~" operationL1 | "-" operationL1 | "+" operationL1 ;
operationL2 = operationL1 { ( "*" | "/" | "%" ) operationL2 } ;
operationL3 = operationL2 { ( "+" | "-" ) operationL2 } ;
operationL4 = operationL3 { ( "<" | ">" ) operationL3 } ;
operationL5 = operationL4 { ( "=" | "<>" ) operationL4 } ;
operationL6 = operationL5 { ( "=" | "<>" ) operationL5 } ;
operationL7 = operationL6 [ ":=" operationL7 ] ;
if = "if" expression "then" expression [ "else" expression ] ;
while = "while" expression "do" expression ;
for = "for" identifier ":" expression ( "to" | "downto" ) expression "do" expression ;
call_args = expression { "," expression } ;
type = "integer" | "array" "[" literal ".." literal "]" "of" type ;