20 void yyerror(const char* str
)
22 fprintf
(stderr
, "%s:%d: %s\n", curfile
, lineno
, str
);
27 %token SET_SIGNAL_MASK RAISE_SIGNAL DO_TURN DO_MOVE DO_SPIN
28 %token ACCELERATE SPEED ALONG AROUND TO SPEED_NOW EXPLODE_TYPE EXPLODE
29 %token DECL_STATIC_VAR DECL_VAR DECL_PIECE EMIT_SFX EMIT_FROM
30 %token START_SCRIPT CALL_SCRIPT RANDOM_NUMBER
31 %token SHADE DONT_SHADE CACHE DONT_CACHE SHOW HIDE
32 %token COB_GET COB_SET COB_SLEEP
33 %token WAIT_FOR_MOVE WAIT_FOR_TURN STOP_SPIN
34 %token ATTACH_UNIT DROP_UNIT
36 %token BOOL_AND BOOL_OR
37 %token PLAY_SOUND CONTINUE BREAK RETURN GOTO
39 %token CMP_EQ CMP_GT CMP_LT CMP_GTE CMP_LTE CMP_NEQ
40 %token INCREMENT DECREMENT FOR WHILE IF ELSE DO SHIFT_LEFT SHIFT_RIGHT
48 %token
<string> IDENTIFIER
49 %token
<number
> NUMBER
52 %type
<ast
> expression primary_expression postfix_expression get_expression
53 %type
<ast
> rand_expression unary_expression additive_expression
54 %type
<ast
> multiplicative_expression shift_expression
55 %type
<ast
> relational_expression equality_expression
56 %type
<ast
> exclusive_or_expression inclusive_or_expression
57 %type
<ast
> and_expression logical_and_expression
58 %type
<ast
> logical_or_expression assignment_expression
59 %type
<ast
> argument_expression_list conditional_expression
61 %start translation_unit
66 : IDENTIFIER
{ $$
= new Ident
($1); }
67 | NUMBER
{ $$
= new Number
($1); }
69 |
'(' expression
')' { $$
= $2; }
70 | rand_expression
{ $$
= $1; }
71 | get_expression
{ $$
= $1;
76 : primary_expression
{ $$
= $1; }
77 | postfix_expression
'(' ')' { $$
= new ASTNode
(); }
78 | postfix_expression
'(' argument_expression_list
')' { $$
= new ASTNode
(); }
79 | postfix_expression INCREMENT
{ $$
= new ASTNode
(); }
80 | postfix_expression DECREMENT
{ $$
= new ASTNode
(); }
84 : COB_GET assignment_expression
{ $$
= new ASTNode
(); }
85 | COB_GET assignment_expression
'(' ')' { $$
= new ASTNode
(); }
86 | COB_GET assignment_expression
'(' assignment_expression
')' { $$
= new ASTNode
(); }
87 | COB_GET assignment_expression
'(' assignment_expression
','
88 assignment_expression
')' { $$
= new ASTNode
(); }
89 | COB_GET assignment_expression
'(' assignment_expression
','
90 assignment_expression
',' assignment_expression
')'
91 { $$
= new ASTNode
(); }
92 | COB_GET assignment_expression
'(' assignment_expression
','
93 assignment_expression
',' assignment_expression
','
94 assignment_expression
')' { $$
= new ASTNode
(); }
98 : RANDOM_NUMBER
'(' assignment_expression
',' assignment_expression
')'
99 { $$
= new ASTNode
(); }
102 argument_expression_list
103 : assignment_expression
{ $$
= $1; }
104 | argument_expression_list
',' assignment_expression
108 : postfix_expression
{ $$
= $1; }
109 | INCREMENT unary_expression
{ $$
= new ASTNode
(); }
110 | DECREMENT unary_expression
{ $$
= new ASTNode
(); }
111 |
'+' unary_expression
{ $$
= new ASTNode
(); }
112 |
'-' unary_expression
{ $$
= new ASTNode
(); }
113 |
'!' unary_expression
{ $$
= new ASTNode
(); }
114 |
'~' unary_expression
{ $$
= new ASTNode
(); }
117 multiplicative_expression
118 : unary_expression
{ $$
= $1; }
119 | multiplicative_expression
'*' unary_expression
{ $$
= new ASTNode
(); }
120 | multiplicative_expression
'/' unary_expression
{ $$
= new ASTNode
(); }
121 | multiplicative_expression
'%' unary_expression
{ $$
= new ASTNode
(); }
125 : multiplicative_expression
{ $$
= $1; }
126 | additive_expression
'+' multiplicative_expression
{ $$
= new ASTNode
(); }
127 | additive_expression
'-' multiplicative_expression
{ $$
= new ASTNode
(); }
131 : additive_expression
132 | shift_expression SHIFT_LEFT additive_expression
{ $$
= new ASTNode
(); }
133 | shift_expression SHIFT_RIGHT additive_expression
{ $$
= new ASTNode
(); }
136 relational_expression
138 | relational_expression
'<' shift_expression
{ $$
= new ASTNode
(); }
139 | relational_expression
'>' shift_expression
{ $$
= new ASTNode
(); }
140 | relational_expression CMP_GTE shift_expression
{ $$
= new ASTNode
(); }
141 | relational_expression CMP_LTE shift_expression
{ $$
= new ASTNode
(); }
145 : relational_expression
146 | equality_expression CMP_EQ relational_expression
{ $$
= new ASTNode
(); }
147 | equality_expression CMP_NEQ relational_expression
{ $$
= new ASTNode
(); }
151 : equality_expression
152 | and_expression
'&' equality_expression
{ $$
= new ASTNode
(); }
155 exclusive_or_expression
157 | exclusive_or_expression
'^' and_expression
{ $$
= new ASTNode
(); }
160 inclusive_or_expression
161 : exclusive_or_expression
162 | inclusive_or_expression
'|' exclusive_or_expression
{ $$
= new ASTNode
(); }
165 logical_and_expression
166 : inclusive_or_expression
167 | logical_and_expression BOOL_AND inclusive_or_expression
{ $$
= new ASTNode
(); }
170 logical_or_expression
171 : logical_and_expression
172 | logical_or_expression BOOL_OR logical_and_expression
{ $$
= new ASTNode
(); }
175 conditional_expression
176 : logical_or_expression
177 | logical_or_expression
'?' expression
':' conditional_expression
178 { $$
= new ASTNode
(); }
181 assignment_expression
182 : conditional_expression
183 | unary_expression
'=' assignment_expression
184 { $$
= new ASTNode
(); }
204 : assignment_expression
205 | expression
',' assignment_expression
209 : conditional_expression
213 : declaration_specifiers
';'
214 | declaration_specifiers init_declarator_list
';'
217 declaration_specifiers
219 | type_specifier declaration_specifiers
224 | init_declarator_list
',' init_declarator
229 | declarator
'=' initializer
238 specifier_qualifier_list
239 : type_specifier specifier_qualifier_list
250 | direct_declarator
'(' parameter_type_list
')'
251 | direct_declarator
'(' identifier_list
')'
252 | direct_declarator
'(' ')'
260 : parameter_declaration
261 | parameter_list
',' parameter_declaration
264 parameter_declaration
265 : declaration_specifiers declarator
266 | declaration_specifiers direct_abstract_declarator
267 | declaration_specifiers
272 | identifier_list
',' IDENTIFIER
276 : specifier_qualifier_list
277 | specifier_qualifier_list direct_abstract_declarator
280 direct_abstract_declarator
281 : '(' direct_abstract_declarator
')'
283 |
'(' parameter_type_list
')'
284 | direct_abstract_declarator
'(' ')'
285 | direct_abstract_declarator
'(' parameter_type_list
')'
289 : assignment_expression
295 | expression_statement
296 | selection_statement
297 | iteration_statement
306 | misc_statement
// cache, shade
308 | visibility_statement
312 | play_sound_statement
317 ///////////////////////////////////////////////////////////////////////
320 : COB_SET expression TO expression
324 : DO_MOVE expression TO AXIS expression SPEED_NOW
325 | DO_MOVE expression TO AXIS expression SPEED expression
326 | DO_MOVE expression TO AXIS expression SPEED expression ACCELERATE expression
327 | DO_TURN expression TO AXIS expression SPEED_NOW
328 | DO_TURN expression TO AXIS expression SPEED expression
329 | DO_TURN expression TO AXIS expression SPEED expression ACCELERATE expression
333 : DO_SPIN expression AROUND AXIS SPEED expression
334 | DO_SPIN expression AROUND AXIS SPEED expression ACCELERATE expression
335 | STOP_SPIN expression
336 | STOP_SPIN expression AROUND AXIS
340 : WAIT_FOR_MOVE expression ALONG AXIS
341 | WAIT_FOR_TURN expression AROUND AXIS
345 : COB_SLEEP expression
349 : EMIT_SFX expression EMIT_FROM expression
353 : CALL_SCRIPT IDENTIFIER
'(' argument_expression_list
')'
354 | CALL_SCRIPT IDENTIFIER
'(' ')'
355 | START_SCRIPT IDENTIFIER
'(' argument_expression_list
')'
356 | START_SCRIPT IDENTIFIER
'(' ')'
359 // mostly no-ops in spring
362 | DONT_CACHE expression
364 | DONT_SHADE expression
368 : ATTACH_UNIT expression TO expression
369 | DROP_UNIT expression
378 : RAISE_SIGNAL expression
379 | SET_SIGNAL_MASK expression
383 : EXPLODE expression EXPLODE_TYPE expression
386 ///////////////////////////////////////////////////////////////////////
389 : IDENTIFIER
':' statement
391 | CASE constant_expression ':' statement
392 | DEFAULT ':' statement
398 |
'{' statement_list
'}'
399 |
'{' declaration_list
'}'
400 |
'{' declaration_list statement_list
'}'
405 | declaration_list declaration
410 | statement_list statement
411 | statement_list declaration_list
412 | statement_list declaration_list statement
421 : IF
'(' expression
')' statement
422 | IF
'(' expression
')' statement ELSE statement
423 /*| SWITCH '(' expression ')' statement*/
427 : WHILE
'(' expression
')' statement
428 | DO statement WHILE
'(' expression
')' ';'
429 | FOR
'(' expression_statement expression_statement
')' statement
430 | FOR
'(' expression_statement expression_statement expression
')' statement
431 // scriptor compatibility
432 | FOR
'(' expression_statement expression_statement expression_statement
')' statement
436 : GOTO IDENTIFIER
';'
440 | RETURN expression
';'
444 : external_declaration
445 | translation_unit external_declaration
450 : function_definition
456 : declarator compound_statement
460 : PRAGMA IDENTIFIER NUMBER
461 | PRAGMA IDENTIFIER IDENTIFIER