Debian Codegraph @

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