diff options
author | David Walter Seikel | 2012-01-12 03:14:17 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-12 03:14:17 +1000 |
commit | fc5d487de27aa7aa17502008c848d06758223888 (patch) | |
tree | 8f3007f53f49c146ae6c30a100decd3b3a0af1dd /LuaSL/src/ANSI_C.y | |
parent | Leaf cloner. (diff) | |
download | SledjHamr-fc5d487de27aa7aa17502008c848d06758223888.zip SledjHamr-fc5d487de27aa7aa17502008c848d06758223888.tar.gz SledjHamr-fc5d487de27aa7aa17502008c848d06758223888.tar.bz2 SledjHamr-fc5d487de27aa7aa17502008c848d06758223888.tar.xz |
Switch to the lemon parser.
Diffstat (limited to 'LuaSL/src/ANSI_C.y')
-rw-r--r-- | LuaSL/src/ANSI_C.y | 471 |
1 files changed, 0 insertions, 471 deletions
diff --git a/LuaSL/src/ANSI_C.y b/LuaSL/src/ANSI_C.y deleted file mode 100644 index 28e2ca2..0000000 --- a/LuaSL/src/ANSI_C.y +++ /dev/null | |||
@@ -1,471 +0,0 @@ | |||
1 | %token IDENTIFIER CONSTANT STRING_LITERAL SIZEOF | ||
2 | %token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP | ||
3 | %token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN | ||
4 | %token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN | ||
5 | %token XOR_ASSIGN OR_ASSIGN TYPE_NAME | ||
6 | |||
7 | %token TYPEDEF EXTERN STATIC AUTO REGISTER INLINE RESTRICT | ||
8 | %token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID | ||
9 | %token BOOL COMPLEX IMAGINARY | ||
10 | %token STRUCT UNION ENUM ELLIPSIS | ||
11 | |||
12 | %token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN | ||
13 | |||
14 | %start translation_unit | ||
15 | %% | ||
16 | |||
17 | primary_expression | ||
18 | : IDENTIFIER | ||
19 | | CONSTANT | ||
20 | | STRING_LITERAL | ||
21 | | '(' expression ')' | ||
22 | ; | ||
23 | |||
24 | postfix_expression | ||
25 | : primary_expression | ||
26 | | postfix_expression '[' expression ']' | ||
27 | | postfix_expression '(' ')' | ||
28 | | postfix_expression '(' argument_expression_list ')' | ||
29 | | postfix_expression '.' IDENTIFIER | ||
30 | | postfix_expression PTR_OP IDENTIFIER | ||
31 | | postfix_expression INC_OP | ||
32 | | postfix_expression DEC_OP | ||
33 | | '(' type_name ')' '{' initializer_list '}' | ||
34 | | '(' type_name ')' '{' initializer_list ',' '}' | ||
35 | ; | ||
36 | |||
37 | argument_expression_list | ||
38 | : assignment_expression | ||
39 | | argument_expression_list ',' assignment_expression | ||
40 | ; | ||
41 | |||
42 | unary_expression | ||
43 | : postfix_expression | ||
44 | | INC_OP unary_expression | ||
45 | | DEC_OP unary_expression | ||
46 | | unary_operator cast_expression | ||
47 | | SIZEOF unary_expression | ||
48 | | SIZEOF '(' type_name ')' | ||
49 | ; | ||
50 | |||
51 | unary_operator | ||
52 | : '&' | ||
53 | | '*' | ||
54 | | '+' | ||
55 | | '-' | ||
56 | | '~' | ||
57 | | '!' | ||
58 | ; | ||
59 | |||
60 | cast_expression | ||
61 | : unary_expression | ||
62 | | '(' type_name ')' cast_expression | ||
63 | ; | ||
64 | |||
65 | multiplicative_expression | ||
66 | : cast_expression | ||
67 | | multiplicative_expression '*' cast_expression | ||
68 | | multiplicative_expression '/' cast_expression | ||
69 | | multiplicative_expression '%' cast_expression | ||
70 | ; | ||
71 | |||
72 | additive_expression | ||
73 | : multiplicative_expression | ||
74 | | additive_expression '+' multiplicative_expression | ||
75 | | additive_expression '-' multiplicative_expression | ||
76 | ; | ||
77 | |||
78 | shift_expression | ||
79 | : additive_expression | ||
80 | | shift_expression LEFT_OP additive_expression | ||
81 | | shift_expression RIGHT_OP additive_expression | ||
82 | ; | ||
83 | |||
84 | relational_expression | ||
85 | : shift_expression | ||
86 | | relational_expression '<' shift_expression | ||
87 | | relational_expression '>' shift_expression | ||
88 | | relational_expression LE_OP shift_expression | ||
89 | | relational_expression GE_OP shift_expression | ||
90 | ; | ||
91 | |||
92 | equality_expression | ||
93 | : relational_expression | ||
94 | | equality_expression EQ_OP relational_expression | ||
95 | | equality_expression NE_OP relational_expression | ||
96 | ; | ||
97 | |||
98 | and_expression | ||
99 | : equality_expression | ||
100 | | and_expression '&' equality_expression | ||
101 | ; | ||
102 | |||
103 | exclusive_or_expression | ||
104 | : and_expression | ||
105 | | exclusive_or_expression '^' and_expression | ||
106 | ; | ||
107 | |||
108 | inclusive_or_expression | ||
109 | : exclusive_or_expression | ||
110 | | inclusive_or_expression '|' exclusive_or_expression | ||
111 | ; | ||
112 | |||
113 | logical_and_expression | ||
114 | : inclusive_or_expression | ||
115 | | logical_and_expression AND_OP inclusive_or_expression | ||
116 | ; | ||
117 | |||
118 | logical_or_expression | ||
119 | : logical_and_expression | ||
120 | | logical_or_expression OR_OP logical_and_expression | ||
121 | ; | ||
122 | |||
123 | conditional_expression | ||
124 | : logical_or_expression | ||
125 | | logical_or_expression '?' expression ':' conditional_expression | ||
126 | ; | ||
127 | |||
128 | assignment_expression | ||
129 | : conditional_expression | ||
130 | | unary_expression assignment_operator assignment_expression | ||
131 | ; | ||
132 | |||
133 | assignment_operator | ||
134 | : '=' | ||
135 | | MUL_ASSIGN | ||
136 | | DIV_ASSIGN | ||
137 | | MOD_ASSIGN | ||
138 | | ADD_ASSIGN | ||
139 | | SUB_ASSIGN | ||
140 | | LEFT_ASSIGN | ||
141 | | RIGHT_ASSIGN | ||
142 | | AND_ASSIGN | ||
143 | | XOR_ASSIGN | ||
144 | | OR_ASSIGN | ||
145 | ; | ||
146 | |||
147 | expression | ||
148 | : assignment_expression | ||
149 | | expression ',' assignment_expression | ||
150 | ; | ||
151 | |||
152 | constant_expression | ||
153 | : conditional_expression | ||
154 | ; | ||
155 | |||
156 | declaration | ||
157 | : declaration_specifiers ';' | ||
158 | | declaration_specifiers init_declarator_list ';' | ||
159 | ; | ||
160 | |||
161 | declaration_specifiers | ||
162 | : storage_class_specifier | ||
163 | | storage_class_specifier declaration_specifiers | ||
164 | | type_specifier | ||
165 | | type_specifier declaration_specifiers | ||
166 | | type_qualifier | ||
167 | | type_qualifier declaration_specifiers | ||
168 | | function_specifier | ||
169 | | function_specifier declaration_specifiers | ||
170 | ; | ||
171 | |||
172 | init_declarator_list | ||
173 | : init_declarator | ||
174 | | init_declarator_list ',' init_declarator | ||
175 | ; | ||
176 | |||
177 | init_declarator | ||
178 | : declarator | ||
179 | | declarator '=' initializer | ||
180 | ; | ||
181 | |||
182 | storage_class_specifier | ||
183 | : TYPEDEF | ||
184 | | EXTERN | ||
185 | | STATIC | ||
186 | | AUTO | ||
187 | | REGISTER | ||
188 | ; | ||
189 | |||
190 | type_specifier | ||
191 | : VOID | ||
192 | | CHAR | ||
193 | | SHORT | ||
194 | | INT | ||
195 | | LONG | ||
196 | | FLOAT | ||
197 | | DOUBLE | ||
198 | | SIGNED | ||
199 | | UNSIGNED | ||
200 | | BOOL | ||
201 | | COMPLEX | ||
202 | | IMAGINARY | ||
203 | | struct_or_union_specifier | ||
204 | | enum_specifier | ||
205 | | TYPE_NAME | ||
206 | ; | ||
207 | |||
208 | struct_or_union_specifier | ||
209 | : struct_or_union IDENTIFIER '{' struct_declaration_list '}' | ||
210 | | struct_or_union '{' struct_declaration_list '}' | ||
211 | | struct_or_union IDENTIFIER | ||
212 | ; | ||
213 | |||
214 | struct_or_union | ||
215 | : STRUCT | ||
216 | | UNION | ||
217 | ; | ||
218 | |||
219 | struct_declaration_list | ||
220 | : struct_declaration | ||
221 | | struct_declaration_list struct_declaration | ||
222 | ; | ||
223 | |||
224 | struct_declaration | ||
225 | : specifier_qualifier_list struct_declarator_list ';' | ||
226 | ; | ||
227 | |||
228 | specifier_qualifier_list | ||
229 | : type_specifier specifier_qualifier_list | ||
230 | | type_specifier | ||
231 | | type_qualifier specifier_qualifier_list | ||
232 | | type_qualifier | ||
233 | ; | ||
234 | |||
235 | struct_declarator_list | ||
236 | : struct_declarator | ||
237 | | struct_declarator_list ',' struct_declarator | ||
238 | ; | ||
239 | |||
240 | struct_declarator | ||
241 | : declarator | ||
242 | | ':' constant_expression | ||
243 | | declarator ':' constant_expression | ||
244 | ; | ||
245 | |||
246 | enum_specifier | ||
247 | : ENUM '{' enumerator_list '}' | ||
248 | | ENUM IDENTIFIER '{' enumerator_list '}' | ||
249 | | ENUM '{' enumerator_list ',' '}' | ||
250 | | ENUM IDENTIFIER '{' enumerator_list ',' '}' | ||
251 | | ENUM IDENTIFIER | ||
252 | ; | ||
253 | |||
254 | enumerator_list | ||
255 | : enumerator | ||
256 | | enumerator_list ',' enumerator | ||
257 | ; | ||
258 | |||
259 | enumerator | ||
260 | : IDENTIFIER | ||
261 | | IDENTIFIER '=' constant_expression | ||
262 | ; | ||
263 | |||
264 | type_qualifier | ||
265 | : CONST | ||
266 | | RESTRICT | ||
267 | | VOLATILE | ||
268 | ; | ||
269 | |||
270 | function_specifier | ||
271 | : INLINE | ||
272 | ; | ||
273 | |||
274 | declarator | ||
275 | : pointer direct_declarator | ||
276 | | direct_declarator | ||
277 | ; | ||
278 | |||
279 | |||
280 | direct_declarator | ||
281 | : IDENTIFIER | ||
282 | | '(' declarator ')' | ||
283 | | direct_declarator '[' type_qualifier_list assignment_expression ']' | ||
284 | | direct_declarator '[' type_qualifier_list ']' | ||
285 | | direct_declarator '[' assignment_expression ']' | ||
286 | | direct_declarator '[' STATIC type_qualifier_list assignment_expression ']' | ||
287 | | direct_declarator '[' type_qualifier_list STATIC assignment_expression ']' | ||
288 | | direct_declarator '[' type_qualifier_list '*' ']' | ||
289 | | direct_declarator '[' '*' ']' | ||
290 | | direct_declarator '[' ']' | ||
291 | | direct_declarator '(' parameter_type_list ')' | ||
292 | | direct_declarator '(' identifier_list ')' | ||
293 | | direct_declarator '(' ')' | ||
294 | ; | ||
295 | |||
296 | pointer | ||
297 | : '*' | ||
298 | | '*' type_qualifier_list | ||
299 | | '*' pointer | ||
300 | | '*' type_qualifier_list pointer | ||
301 | ; | ||
302 | |||
303 | type_qualifier_list | ||
304 | : type_qualifier | ||
305 | | type_qualifier_list type_qualifier | ||
306 | ; | ||
307 | |||
308 | |||
309 | parameter_type_list | ||
310 | : parameter_list | ||
311 | | parameter_list ',' ELLIPSIS | ||
312 | ; | ||
313 | |||
314 | parameter_list | ||
315 | : parameter_declaration | ||
316 | | parameter_list ',' parameter_declaration | ||
317 | ; | ||
318 | |||
319 | parameter_declaration | ||
320 | : declaration_specifiers declarator | ||
321 | | declaration_specifiers abstract_declarator | ||
322 | | declaration_specifiers | ||
323 | ; | ||
324 | |||
325 | identifier_list | ||
326 | : IDENTIFIER | ||
327 | | identifier_list ',' IDENTIFIER | ||
328 | ; | ||
329 | |||
330 | type_name | ||
331 | : specifier_qualifier_list | ||
332 | | specifier_qualifier_list abstract_declarator | ||
333 | ; | ||
334 | |||
335 | abstract_declarator | ||
336 | : pointer | ||
337 | | direct_abstract_declarator | ||
338 | | pointer direct_abstract_declarator | ||
339 | ; | ||
340 | |||
341 | direct_abstract_declarator | ||
342 | : '(' abstract_declarator ')' | ||
343 | | '[' ']' | ||
344 | | '[' assignment_expression ']' | ||
345 | | direct_abstract_declarator '[' ']' | ||
346 | | direct_abstract_declarator '[' assignment_expression ']' | ||
347 | | '[' '*' ']' | ||
348 | | direct_abstract_declarator '[' '*' ']' | ||
349 | | '(' ')' | ||
350 | | '(' parameter_type_list ')' | ||
351 | | direct_abstract_declarator '(' ')' | ||
352 | | direct_abstract_declarator '(' parameter_type_list ')' | ||
353 | ; | ||
354 | |||
355 | initializer | ||
356 | : assignment_expression | ||
357 | | '{' initializer_list '}' | ||
358 | | '{' initializer_list ',' '}' | ||
359 | ; | ||
360 | |||
361 | initializer_list | ||
362 | : initializer | ||
363 | | designation initializer | ||
364 | | initializer_list ',' initializer | ||
365 | | initializer_list ',' designation initializer | ||
366 | ; | ||
367 | |||
368 | designation | ||
369 | : designator_list '=' | ||
370 | ; | ||
371 | |||
372 | designator_list | ||
373 | : designator | ||
374 | | designator_list designator | ||
375 | ; | ||
376 | |||
377 | designator | ||
378 | : '[' constant_expression ']' | ||
379 | | '.' IDENTIFIER | ||
380 | ; | ||
381 | |||
382 | statement | ||
383 | : labeled_statement | ||
384 | | compound_statement | ||
385 | | expression_statement | ||
386 | | selection_statement | ||
387 | | iteration_statement | ||
388 | | jump_statement | ||
389 | ; | ||
390 | |||
391 | labeled_statement | ||
392 | : IDENTIFIER ':' statement | ||
393 | | CASE constant_expression ':' statement | ||
394 | | DEFAULT ':' statement | ||
395 | ; | ||
396 | |||
397 | compound_statement | ||
398 | : '{' '}' | ||
399 | | '{' block_item_list '}' | ||
400 | ; | ||
401 | |||
402 | block_item_list | ||
403 | : block_item | ||
404 | | block_item_list block_item | ||
405 | ; | ||
406 | |||
407 | block_item | ||
408 | : declaration | ||
409 | | statement | ||
410 | ; | ||
411 | |||
412 | expression_statement | ||
413 | : ';' | ||
414 | | expression ';' | ||
415 | ; | ||
416 | |||
417 | selection_statement | ||
418 | : IF '(' expression ')' statement | ||
419 | | IF '(' expression ')' statement ELSE statement | ||
420 | | SWITCH '(' expression ')' statement | ||
421 | ; | ||
422 | |||
423 | iteration_statement | ||
424 | : WHILE '(' expression ')' statement | ||
425 | | DO statement WHILE '(' expression ')' ';' | ||
426 | | FOR '(' expression_statement expression_statement ')' statement | ||
427 | | FOR '(' expression_statement expression_statement expression ')' statement | ||
428 | | FOR '(' declaration expression_statement ')' statement | ||
429 | | FOR '(' declaration expression_statement expression ')' statement | ||
430 | ; | ||
431 | |||
432 | jump_statement | ||
433 | : GOTO IDENTIFIER ';' | ||
434 | | CONTINUE ';' | ||
435 | | BREAK ';' | ||
436 | | RETURN ';' | ||
437 | | RETURN expression ';' | ||
438 | ; | ||
439 | |||
440 | translation_unit | ||
441 | : external_declaration | ||
442 | | translation_unit external_declaration | ||
443 | ; | ||
444 | |||
445 | external_declaration | ||
446 | : function_definition | ||
447 | | declaration | ||
448 | ; | ||
449 | |||
450 | function_definition | ||
451 | : declaration_specifiers declarator declaration_list compound_statement | ||
452 | | declaration_specifiers declarator compound_statement | ||
453 | ; | ||
454 | |||
455 | declaration_list | ||
456 | : declaration | ||
457 | | declaration_list declaration | ||
458 | ; | ||
459 | |||
460 | |||
461 | %% | ||
462 | #include <stdio.h> | ||
463 | |||
464 | extern char yytext[]; | ||
465 | extern int column; | ||
466 | |||
467 | void yyerror(char const *s) | ||
468 | { | ||
469 | fflush(stdout); | ||
470 | printf("\n%*s\n%*s\n", column, "^", column, s); | ||
471 | } | ||