This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar
115 lines (82 loc) · 1.76 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
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
program : PROGRAM ID ';' variable_declaration function_declaration block
empty :
variable_declaration : type ids ';' variable_declaration
| empty
ids : id other_ids
other_ids : ',' ids
| empty
id : ID
| ID '[' expression ']'
expression : level1
| level1 EXPONENTIATION level1
level1 : level2
| '+' level2
| '-' level2
level2 : level3
| level3 OR level3
| level3 AND level3
level3 : level4
| level4 '<' level4
| level4 '>' level4
| level4 LESS_EQUAL_THAN level4
| level4 GREATER_EQUAL_THAN level4
| level4 EQUALS level4
level4 : level5
| level5 '+' level5
| level5 '-' level5
level5 : level6
| NOT level6
| level6 '*' level6
| level6 '/' level6
| level6 MOD level6
level6 : '(' expression ')'
| const
| increment
| decrement
increment : INCREMENT id
decrement : DECREMENT id
function_declaration : function function_declaration
| empty
'''function : FUN return_type ID '(' parameters ')' '{' variable_declaration statutes '}' ';'
return_type : type
| VOID
type : INT
| DEC
| CHAR
| STR
| BOOL
statutes : statute ';' statutes
| empty
'''statute : call
| assignment
| condition
| cycle
| special
| return
| increment
| decrement
call : ID '(' expressions ')'
expressions : expression
| expression ',' expressions
assignment : id '=' expression
condition : IF '(' expression ')' block elses
cycle : WHILE '(' expression ')' block
special : SPECIAL_ID '(' expressions ')'
return : RETURN expression
| RETURN
elses : empty
| ELSE block
| ELSEIF '(' expression ')' block elses
parameters : type ID other_parameters
| empty
other_parameters : ',' type ID other_parameters
| empty
const : id
| call
| special
| INT_VAL
| DEC_VAL
| CHAR_VAL
| STR_VAL
| BOOL_VAL
block : '{' statutes '}'