-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgramatica.txt
187 lines (134 loc) · 3.48 KB
/
gramatica.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
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
S' : prog
prog : global_declarations function_declarations
global_declarations : global_declaration global_declarations
|
global_declaration : declaration
| declaration_assignment
function_declarations : function_declaration function_declarations
|
function_declaration : function_header function_body
function_header : function_id ss ( params ) out_type
function_id : FUNCTION ID
function_body : { stmts } es
function_call : f_call ( args )
f_call : ID
params : params , param
| param
|
param : ID : type
| ID : Ptype
out_type : RARROW type
| RARROW Ptype
|
args : args , arg
| arg
|
arg : expression
stmts : stmt stmts
|
stmt : print
| read
| function_call
| declaration_assignment
| assignment
| declaration
| if
| match
| while
| for
| do_while
| break
| continue
| return
ss :
es :
return : RETURN expression
| RETURN ;
break : BREAK
continue : CONTINUE
for : loop_for ss ( for_inits ; expression ; for_updates ) ss { stmts } es es
for_inits : for_inits , for_init
| for_init
for_init : declaration_assignment
| declaration
| assignment
|
for_updates : for_updates , for_update
| for_update
for_update : assignment
loop_for : FOR
do_while : loop_do ss { stmts } es WHILE ( expression )
loop_do : DO
while : loop_while expression ss { stmts } es
loop_while : WHILE
if : IF expression ss { stmts } es else_if
else_if : ELSE IF expression ss { stmts } es else_if
| else
else : ELSE ss { stmts } es
|
match : match_start expression { cases }
match_start : MATCH
cases : expression RARROW ss { stmts } es cases
| default
default : DEFAULT RARROW ss { stmts } es
declaration_assignment : ID : type ASSIGN expression
| ID : Ptype ASSIGN expression
| ID : Vtype ASSIGN [ arrayitems ]
| ID : Vtype ASSIGN [ INTEGER RETI INTEGER ]
arrayitems : arrayitems , expression
| expression
declaration : ID : type
| ID : Ptype
| ID : Vtype ndim
ndim : ndim [ INTEGER ]
| [ INTEGER ]
assignment : ID ndepth ASSIGN expression
| ID ASSIGN expression
ndepth : ndepth [ expression ]
| [ expression ]
read : read_type ( multiple_prints )
read_type : READ_INT
| READ_FLOAT
| READ_STRING
print : PRINT ( multiple_prints )
multiple_prints : multiple_prints , expression
| expression
|
type : TYPE_INT
| TYPE_STRING
| TYPE_FLOAT
Vtype : TYPE_VEC LT type GT
Ptype : & TYPE_INT
| & TYPE_STRING
| & TYPE_FLOAT
expression : expression OR subexpression
| subexpression
subexpression : subexpression AND condition
| condition
condition : condition EQ comparison
| condition NEQ comparison
| comparison
comparison : comparison LT term
| comparison GT term
| comparison LTE term
| comparison GTE term
| term
term : term - factor
| term + factor
| factor
factor : factor * unary
| factor / unary
| factor % unary
| unary
unary : ! unary
| - unary
| primary
primary : ID ndepth
| & ID
| INTEGER
| FLOAT
| FILUM
| ID
| function_call
| read
| ( expression )