Debian Codegraph @

extern/btyacc/test/ansiC2.y

raw
1 %token AUTO REGISTER STATIC EXTERN TYPEDEF VOID CHAR SHORT INT LONG FLOAT
2 DOUBLE SIGNED UNSIGNED CONST VOLATILE STRUCT UNION ENUM CASE DEFAULT
3 IF SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN ELSE
4 MULEQ DIVEQ MODEQ ADDEQ SUBEQ LSHEQ RSHEQ ANDEQ XOREQ OREQ
5 AND OR EQU NEQ LEQ GEQ LSH RSH INC DEC ARROW IDENTIFIER STRING
6 INTCONST CHARCONST FLOATCONST ELIPSIS SIZEOF
7
8 %%
9
10 translation.unit
11 : external.declaration
12 | translation.unit external.declaration
13 ;
14
15 external.declaration
16 : function.definition
17 | declaration
18 ;
19
20 function.definition
21 : declaration.specifiers declarator declaration.list.opt compound.statement
22 | declarator declaration.list.opt compound.statement
23 ;
24
25 declaration.specifiers.opt
26 :
27 | declaration.specifiers
28 ;
29
30 declaration.list.opt
31 :
32 | declaration.list
33 ;
34
35 declaration
36 : declaration.specifiers init.declarator.list.opt ';'
37 ;
38
39 declaration.list
40 : declaration
41 | declaration.list declaration
42 ;
43
44 declaration.specifiers
45 : storage.class.specifier declaration.specifiers.opt
46 | type.specifier declaration.specifiers.opt
47 | type.qualifier declaration.specifiers.opt
48 ;
49
50 storage.class.specifier
51 : AUTO
52 | REGISTER
53 | STATIC
54 | EXTERN
55 | TYPEDEF
56 ;
57
58 type.specifier
59 : VOID
60 | CHAR
61 | SHORT
62 | INT
63 | LONG
64 | FLOAT
65 | DOUBLE
66 | SIGNED
67 | UNSIGNED
68 | struct.or.union.specifier
69 | enum.specifier
70 | typedef.name
71 ;
72
73 type.qualifier
74 : CONST
75 | VOLATILE
76 ;
77
78 struct.or.union.specifier
79 : struct.or.union identifier.opt '{' struct.declaration.list '}'
80 | struct.or.union IDENTIFIER
81 ;
82
83 struct.or.union
84 : STRUCT
85 | UNION
86 ;
87
88 struct.declaration.list
89 : struct.declaration
90 | struct.declaration.list struct.declaration
91 ;
92
93 init.declarator.list.opt
94 :
95 | init.declarator.list
96 ;
97
98 init.declarator.list
99 : init.declarator
100 | init.declarator.list ',' init.declarator
101 ;
102
103 init.declarator
104 : declarator
105 | declarator '=' initializer
106 ;
107
108 struct.declaration
109 : specifier.qualifier.list struct.declarator.list ';'
110 ;
111
112 specifier.qualifier.list.opt
113 :
114 | specifier.qualifier.list
115 ;
116
117 specifier.qualifier.list
118 : type.specifier specifier.qualifier.list.opt
119 | type.qualifier specifier.qualifier.list.opt
120 ;
121
122 struct.declarator.list
123 : struct.declarator
124 | struct.declarator.list ',' struct.declarator
125 ;
126
127 struct.declarator
128 : declarator
129 | declarator.opt ':' constant.expression
130 ;
131
132 enum.specifier
133 : ENUM identifier.opt '{' enumerator.list '}'
134 | ENUM IDENTIFIER
135 ;
136
137 enumerator.list
138 : enumerator
139 | enumerator.list ',' enumerator
140 ;
141
142 enumerator
143 : IDENTIFIER
144 | IDENTIFIER '=' constant.expression
145 ;
146
147 declarator.opt
148 :
149 | declarator
150 ;
151
152 declarator
153 : pointer.opt direct.declarator
154 ;
155
156 direct.declarator
157 : IDENTIFIER
158 | '(' declarator ')'
159 | direct.declarator '[' constant.expression ']'
160 | direct.declarator '(' parameter.type.list ')'
161 | direct.declarator '(' identifier.list.opt ')'
162 ;
163
164 pointer.opt
165 :
166 | pointer
167 ;
168
169 pointer : '*' type.qualifier.list.opt
170 | '*' type.qualifier.list.opt pointer
171 ;
172
173 type.qualifier.list.opt
174 :
175 | type.qualifier.list
176 ;
177
178 type.qualifier.list
179 : type.qualifier
180 | type.qualifier.list type.qualifier
181 ;
182
183 parameter.type.list.opt
184 :
185 | parameter.type.list
186 ;
187
188 parameter.type.list
189 : parameter.list
190 | parameter.list ',' ELIPSIS
191 ;
192
193 parameter.list
194 : parameter.declaration
195 | parameter.list ',' parameter.declaration
196 ;
197
198 parameter.declaration
199 : declaration.specifiers declarator
200 | declaration.specifiers abstract.declarator.opt
201 ;
202
203 identifier.list.opt
204 :
205 | identifier.list
206 ;
207
208 identifier.list
209 : IDENTIFIER
210 | identifier.list ',' IDENTIFIER
211 ;
212
213 initializer
214 : assignment.expression
215 | '{' initializer.list '}'
216 | '{' initializer.list ',' '}'
217 ;
218
219
220 initializer.list
221 : initializer
222 | initializer.list ',' initializer
223 ;
224
225 type.name
226 : specifier.qualifier.list abstract.declarator.opt
227 ;
228
229 abstract.declarator.opt
230 :
231 | abstract.declarator
232 ;
233
234 abstract.declarator
235 : pointer
236 | pointer.opt direct.abstract.declarator
237 ;
238
239 direct.abstract.declarator.opt
240 :
241 | direct.abstract.declarator
242 ;
243
244 direct.abstract.declarator
245 : '(' abstract.declarator ')'
246 | direct.abstract.declarator.opt '[' constant.expression.opt ']'
247 | direct.abstract.declarator '(' parameter.type.list.opt ')'
248 | '(' parameter.type.list.opt ')'
249 ;
250
251 typedef.name
252 : IDENTIFIER
253 ;
254
255 identifier.opt
256 :
257 | IDENTIFIER
258 ;
259
260 statement
261 : labeled.statement
262 | expression.statement
263 | compound.statement
264 | selection.statement
265 | iteration.statement
266 | jump.statement
267 ;
268
269 labeled.statement
270 : IDENTIFIER ':' statement
271 | CASE constant.expression ':' statement
272 | DEFAULT ':' statement
273 ;
274
275 expression.statement
276 : expression.opt ';'
277 ;
278
279 compound.statement
280 : '{' declaration.list.opt statement.list.opt '}'
281 ;
282
283 statement.list.opt
284 :
285 | statement.list
286 ;
287
288 statement.list
289 : statement
290 | statement.list statement
291 ;
292
293 selection.statement
294 : IF '(' expression ')' statement
295 | IF '(' expression ')' statement ELSE statement
296 | SWITCH '(' expression ')' statement
297 ;
298
299 iteration.statement
300 : WHILE '(' expression ')' statement
301 | DO statement WHILE '(' expression ')' ';'
302 | FOR '(' expression.opt ';' expression.opt ';' expression.opt ')' statement
303 ;
304
305 jump.statement
306 : GOTO IDENTIFIER ';'
307 | CONTINUE ';'
308 | BREAK ';'
309 | RETURN expression.opt ';'
310 ;
311
312 expression.opt
313 :
314 | expression
315 ;
316
317 constant.expression.opt
318 :
319 | constant.expression
320 ;
321
322 constant.expression
323 : assignment.expression
324 ;
325
326 expression
327 : assignment.expression
328 | expression ',' assignment.expression
329 ;
330
331 assignment.expression
332 : conditional.expression
333 | unary.expression assignment.operator assignment.expression
334 ;
335
336 assignment.operator
337 : '=' | MULEQ | DIVEQ | MODEQ | ADDEQ | SUBEQ
338 | LSHEQ | RSHEQ | ANDEQ | XOREQ | OREQ
339 ;
340
341 conditional.expression
342 : logical.OR.expression
343 | logical.OR.expression '?' expression ':' conditional.expression
344 ;
345
346 logical.OR.expression
347 : logical.AND.expression
348 | logical.OR.expression OR logical.AND.expression
349 ;
350
351 logical.AND.expression
352 : inclusive.OR.expression
353 | logical.AND.expression AND inclusive.OR.expression
354 ;
355
356 inclusive.OR.expression
357 : exclusive.OR.expression
358 | inclusive.OR.expression '|' exclusive.OR.expression
359 ;
360
361 exclusive.OR.expression
362 : AND.expression
363 | exclusive.OR.expression '^' AND.expression
364 ;
365
366 AND.expression
367 : equality.expression
368 | AND.expression '&' equality.expression
369 ;
370
371 equality.expression
372 : relational.expression
373 | equality.expression EQU relational.expression
374 | equality.expression NEQ relational.expression
375 ;
376
377 relational.expression
378 : shift.expression
379 | relational.expression '<' shift.expression
380 | relational.expression '>' shift.expression
381 | relational.expression LEQ shift.expression
382 | relational.expression GEQ shift.expression
383 ;
384
385 shift.expression
386 : additive.expression
387 | shift.expression LSH additive.expression
388 | shift.expression RSH additive.expression
389 ;
390
391 additive.expression
392 : multiplicative.expression
393 | additive.expression '+' multiplicative.expression
394 | additive.expression '-' multiplicative.expression
395 ;
396
397 multiplicative.expression
398 : cast.expression
399 | multiplicative.expression '*' cast.expression
400 | multiplicative.expression '/' cast.expression
401 | multiplicative.expression '%' cast.expression
402 ;
403
404 cast.expression
405 : unary.expression
406 | '(' type.name ')' cast.expression
407 ;
408
409 unary.expression
410 : postfix.expression
411 | INC unary.expression
412 | DEC unary.expression
413 | unary.operator cast.expression
414 | SIZEOF unary.expression
415 | SIZEOF '(' type.name ')'
416 ;
417
418 unary.operator
419 : '&' | '*' | '+' | '-' | '~' | '!'
420 ;
421
422 postfix.expression
423 : primary.expression
424 | postfix.expression '[' expression ']'
425 | postfix.expression '(' argument.expression.list.opt ')'
426 | postfix.expression '.' IDENTIFIER
427 | postfix.expression ARROW IDENTIFIER
428 | postfix.expression INC
429 | postfix.expression DEC
430 ;
431
432 primary.expression
433 : IDENTIFIER
434 | constant
435 | STRING
436 | '(' expression ')'
437 ;
438
439 argument.expression.list.opt
440 :
441 | argument.expression.list
442 ;
443
444 argument.expression.list
445 : assignment.expression
446 | argument.expression.list ',' assignment.expression
447 ;
448
449 constant
450 : INTCONST
451 | CHARCONST
452 | FLOATCONST
453 ;
454