-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grammar.3txt
73 lines (53 loc) · 1.38 KB
/
Grammar.3txt
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
start: procedure+
procedure: "procedure" NAME paramsdeclare codeblock
variabledeclare: NAME ":" TYPE
variable : NAME
paramsdeclare : "("")"
| "(" variabledeclare ")"
| "(" variabledeclare ("," variabledeclare)+ ")"
codeblock : "{" instruction* "}"
instruction: expression?
| assignment?
| variabledeclare?
assignment: variable "=" expression
expression: mathexpression
| boolexpression
| procedureexprssion
mathexpression: sum
?sum: product
| sum "+" product
| sum "-" product
?product: atom
| product "*" atom
| product "/" atom
?atom: NUMBER
| "-" atom
| variablename
| array
| "(" sum ")"
boolexpression: boolsum
?boolsum: boolproduct
| boolsum "<" boolproduct
| boolsum ">" boolproduct
| boolsum "==" boolproduct
| boolsum "=<" boolproduct
| boolsum "=>" boolproduct
| boolsum "=!" boolproduct
| boolsum "||" boolproduct
?boolproduct: boolatom
| boolproduct "&&" boolatom
?boolatom: BOOL
| sum
| "!" atom
| variablename
| array
| "(" boolsum ")"
procedureexprssion: variablename params
params: "("")"
| "(" variablename ")"
| "(" variablename ("," variablename)+ ")"
| "(" expression ")"
| "(" expression ("," expression)+ ")"
NAME: /[A-Za-z][A-Za-z0-9_]*/
NUMBER: /\d+\.?\d*/
TYPE: "Integer" | "String"