14 extern
double linear_const
, angular_const
;
22 void yyerror(const char* str
)
24 fprintf
(stderr
, "%s:%d: %s\n", curfile
, lineno
, str
);
28 RootBlock
*root
= new RootBlock
();
33 %token SET_SIGNAL_MASK RAISE_SIGNAL DO_TURN DO_MOVE DO_SPIN
34 %token ACCELERATE SPEED ALONG AROUND TO SPEED_NOW EXPLODE_TYPE EXPLODE
35 %token DECL_STATIC_VAR DECL_VAR DECL_PIECE EMIT_SFX EMIT_FROM
36 %token START_SCRIPT CALL_SCRIPT RANDOM_NUMBER
37 %token SHADE DONT_SHADE CACHE DONT_CACHE SHOW HIDE
38 %token COB_GET COB_SET COB_SLEEP
39 %token WAIT_FOR_MOVE WAIT_FOR_TURN STOP_SPIN
40 %token ATTACH_UNIT DROP_UNIT
42 %token BOOL_AND
"&&" BOOL_OR
"||"
43 %token PLAY_SOUND CONTINUE BREAK RETURN GOTO
45 %token CMP_EQ
"==" CMP_GT CMP_LT CMP_GTE
">=" CMP_LTE
"<=" CMP_NEQ
"!="
46 %token INCREMENT
"++" DECREMENT
"--" FOR WHILE IF ELSE DO
47 %token SHIFT_LEFT
"<<" SHIFT_RIGHT
">>"
49 %token ANGULAR_EXPR_OPEN
"<("
50 %token ANGULAR_EXPR_CLOSE
")>"
58 %token
<string> IDENTIFIER
59 %token
<number
> NUMBER
62 %type
<ast
> expression primary_expression postfix_expression get_expression
63 %type
<ast
> rand_expression unary_expression additive_expression
64 %type
<ast
> multiplicative_expression shift_expression
65 %type
<ast
> relational_expression equality_expression
66 %type
<ast
> exclusive_or_expression inclusive_or_expression
67 %type
<ast
> and_expression logical_and_expression
68 %type
<ast
> logical_or_expression assignment_expression
69 %type
<ast
> argument_expression_list conditional_expression
70 //%type <ast> constant_expression
72 %type
<ast
> statement expression_statement jump_statement
73 %type
<ast
> selection_statement iteration_statement
74 %type
<ast
> set_statement labeled_statement
75 %type
<ast
> compound_statement move_statement spin_statement
76 %type
<ast
> wait_statement sleep_statement emit_sfx_statement
77 %type
<ast
> script_statement misc_statement attach_statement
78 %type
<ast
> visibility_statement explode_statement signal_statement
79 %type
<ast
> declaration_list declaration
80 %type
<ast
> statement_list
82 %type
<ast
> type_specifier init_declarator_list init_declarator declarator
83 %type
<ast
> initializer identifier_list pragma function_definition
84 %type
<ast
> translation_unit external_declaration
87 %start translation_unit
95 : IDENTIFIER
{ $$
= new Ident
($1); }
96 | NUMBER
{ $$
= new Number
($1); }
97 | AXIS
{ $$
= new Axis
($1); }
99 |
'(' expression
')' { $$
= $2; }
100 |
'[' expression
']' { $$
= new Multiply
(new Number
(linear_const
), $2); }
101 //| '<' expression '>' { $$ = new Multiply(new Number(angular_const), $2); }
102 |
"<(" expression
")>" { $$
= new Multiply
(new Number
(angular_const
), $2); }
107 | postfix_expression
'(' ')' { $$
= new CallExpr
($1, 0); }
108 | postfix_expression
'(' argument_expression_list
')' { $$
= new CallExpr
($1, $3); }
109 | postfix_expression INCREMENT
{ $$
= new Increment
($1); }
110 | postfix_expression DECREMENT
{ $$
= new Decrement
($1); }
114 argument_expression_list
115 : assignment_expression
116 | argument_expression_list
',' assignment_expression
{ $$
= new Comma
($1, $3) }
121 | INCREMENT unary_expression
{ $$
= new Increment
($2); }
122 | DECREMENT unary_expression
{ $$
= new Decrement
($2); }
123 |
'+' unary_expression
{ $$
= $2; }
124 |
'-' unary_expression
{ $$
= new Negation
($2); }
125 |
'!' unary_expression
{ $$
= new LogicalNot
($2); }
126 |
'~' unary_expression
{ $$
= new BitwiseNot
($2); }
132 : COB_GET primary_expression
{ $$
= new GetOp
($2); }
133 | COB_GET primary_expression
'(' ')' { $$
= new GetOp
($2); }
134 | COB_GET primary_expression
'(' assignment_expression
')'
135 { $$
= new GetOp
($2, $4); }
136 | COB_GET primary_expression
'(' assignment_expression
','
137 assignment_expression
')' { $$
= new GetOp
($2, $4, $6); }
138 | COB_GET primary_expression
'(' assignment_expression
','
139 assignment_expression
',' assignment_expression
')'
140 { $$
= new GetOp
($2, $4, $6, $8); }
141 | COB_GET primary_expression
'(' assignment_expression
','
142 assignment_expression
',' assignment_expression
','
143 assignment_expression
')' { $$
= new GetOp
($2, $4, $6, $8, $10); }
147 : RANDOM_NUMBER
'(' assignment_expression
',' assignment_expression
')'
148 { $$
= new TAOperation
("rand", $3, $5); }
151 multiplicative_expression
153 | multiplicative_expression
'*' unary_expression
{ $$
= new Multiply
($1, $3); }
154 | multiplicative_expression
'/' unary_expression
{ $$
= new Divide
($1, $3); }
155 | multiplicative_expression
'%' unary_expression
{ $$
= new Modulo
($1, $3); }
159 : multiplicative_expression
160 | additive_expression
'+' multiplicative_expression
{ $$
= new Add
($1, $3); }
161 | additive_expression
'-' multiplicative_expression
{ $$
= new Subtract
($1, $3); }
165 : additive_expression
166 | shift_expression SHIFT_LEFT additive_expression
{ $$
= new ShiftLeft
($1, $3); }
167 | shift_expression SHIFT_RIGHT additive_expression
{ $$
= new ShiftRight
($1, $3); }
170 relational_expression
172 | relational_expression
'<' shift_expression
{ $$
= new LessThan
($1, $3); }
173 | relational_expression
'>' shift_expression
{ $$
= new GreaterThan
($1, $3); }
174 | relational_expression CMP_GTE shift_expression
{ $$
= new GreaterEqual
($1, $3); }
175 | relational_expression CMP_LTE shift_expression
{ $$
= new LessEqual
($1, $3); }
179 : relational_expression
180 | equality_expression CMP_EQ relational_expression
{ $$
= new Equal
($1, $3); }
181 | equality_expression CMP_NEQ relational_expression
{ $$
= new NotEqual
($1, $3); }
185 : equality_expression
186 | and_expression
'&' equality_expression
{ $$
= new BitwiseAnd
($1, $3); }
189 exclusive_or_expression
191 | exclusive_or_expression
'^' and_expression
{ $$
= new BitwiseXor
($1, $3); }
194 inclusive_or_expression
195 : exclusive_or_expression
196 | inclusive_or_expression
'|' exclusive_or_expression
{ $$
= new BitwiseOr
($1, $3); }
199 logical_and_expression
200 : inclusive_or_expression
201 | logical_and_expression BOOL_AND inclusive_or_expression
{ $$
= new LogicalOr
($1, $3); }
204 logical_or_expression
205 : logical_and_expression
206 | logical_or_expression BOOL_OR logical_and_expression
{ $$
= new LogicalAnd
($1, $3); }
210 conditional_expression
211 : logical_or_expression
212 | logical_or_expression
'?' expression
':' conditional_expression
213 { $$
= new IfThenElse
($1, $3, $5); }
216 assignment_expression
217 : conditional_expression
219 // | unary_expression '=' assignment_expression
220 | IDENTIFIER
'=' assignment_expression
221 { $$
= new Assign
(new Ident
($1), $3); }
241 : assignment_expression
242 | expression
',' assignment_expression
{ $$
= new Comma
($1, $3); }
247 : conditional_expression
252 : type_specifier
';' { $$
= $1; }
253 | type_specifier init_declarator_list
';' { $$
= new Declaration
($1, $2); }
259 | init_declarator_list
',' init_declarator
{ $$
= new Comma
($1, $3); }
264 | declarator
'=' initializer
{ $$
= new Assign
($1, $3); }
268 : DECL_STATIC_VAR
{ $$
= new Typename
("static-var"); }
269 | DECL_VAR
{ $$
= new Typename
("var"); }
270 | DECL_PIECE
{ $$
= new Typename
("piece"); }
274 : IDENTIFIER
{ $$
= new Ident
($1) }
275 |
'(' declarator
')' { $$
= $2 }
276 | IDENTIFIER
'(' identifier_list
')' { $$
= new FunctionProto
($1, $3) }
277 | IDENTIFIER
'(' ')' { $$
= new FunctionProto
($1, 0) }
281 : IDENTIFIER
{ $$
= new Ident
($1) }
282 | identifier_list
',' IDENTIFIER
{ $$
= new Comma
($1, new Ident
($3)) }
286 : assignment_expression
292 | expression_statement
293 | selection_statement
294 | iteration_statement
304 | misc_statement
// cache, shade
306 | visibility_statement
310 | play_sound_statement
315 ///////////////////////////////////////////////////////////////////////
318 : COB_SET expression TO expression
{ $$
= new SetOp
($2, $4); }
322 : DO_MOVE expression TO primary_expression expression SPEED_NOW
323 { $$
= new TAOperation
("move-now", $2, $4, $5); }
324 | DO_MOVE expression TO primary_expression expression SPEED expression
325 { $$
= new TAOperation
("move", $2, $4, $5, $7); }
326 | DO_MOVE expression TO primary_expression expression SPEED expression ACCELERATE expression
327 { $$
= new TAOperation
("move", $2, $4, $5, $7, $9); }
328 | DO_TURN expression TO primary_expression expression SPEED_NOW
329 { $$
= new TAOperation
("turn-now", $2, $4, $5); }
330 | DO_TURN expression TO primary_expression expression SPEED expression
331 { $$
= new TAOperation
("turn", $2, $4, $5, $7); }
332 | DO_TURN expression TO primary_expression expression SPEED expression ACCELERATE expression
333 { $$
= new TAOperation
("turn", $2, $4, $5, $7, $9); }
337 : DO_SPIN expression AROUND expression SPEED expression
338 { $$
= new TAOperation
("spin", $2, $4, $6); }
339 | DO_SPIN expression AROUND expression SPEED expression ACCELERATE expression
340 { $$
= new TAOperation
("spin", $2, $4, $6, $8); }
341 | STOP_SPIN expression
342 { $$
= new TAOperation
("stop-spin", $2); }
343 | STOP_SPIN expression AROUND expression
344 { $$
= new TAOperation
("stop-spin", $2, $4); }
348 : WAIT_FOR_MOVE expression ALONG expression
349 { $$
= new TAOperation
("wait-for-move", $2, $4); }
350 | WAIT_FOR_TURN expression AROUND expression
351 { $$
= new TAOperation
("wait-for-turn", $2, $4); }
355 : COB_SLEEP expression
356 { $$
= new TAOperation
("sleep", $2); }
360 : EMIT_SFX expression EMIT_FROM expression
361 { $$
= new TAOperation
("emit-sfx", $2, $4); }
365 : CALL_SCRIPT IDENTIFIER
'(' argument_expression_list
')'
366 { $$
= new Call
($2, $4); }
367 | CALL_SCRIPT IDENTIFIER
'(' ')'
368 { $$
= new Call
($2); }
369 | START_SCRIPT IDENTIFIER
'(' argument_expression_list
')'
370 { $$
= new StartScript
($2, $4); }
371 | START_SCRIPT IDENTIFIER
'(' ')'
372 { $$
= new StartScript
($2); }
375 // mostly no-ops in spring
377 : CACHE expression
{ $$
= $2 }
378 | DONT_CACHE expression
{ $$
= $2 }
379 | SHADE expression
{ $$
= $2 }
380 | DONT_SHADE expression
{ $$
= $2 }
384 : ATTACH_UNIT expression TO expression
385 { $$
= new TAOperation
("attach-unit", $2, $4); }
386 | DROP_UNIT expression
387 { $$
= new TAOperation
("drop-unit", $2); }
392 { $$
= new TAOperation
("show", $2); }
394 { $$
= new TAOperation
("hide", $2); }
398 : RAISE_SIGNAL expression
399 { $$
= new TAOperation
("signal", $2); }
400 | SET_SIGNAL_MASK expression
401 { $$
= new TAOperation
("set-signal-mask", $2); }
405 : EXPLODE expression EXPLODE_TYPE expression
406 { $$
= new TAOperation
("explode", $2, $4); }
409 ///////////////////////////////////////////////////////////////////////
412 : IDENTIFIER
':' statement
{ $$
= new Label
($1, $3); }
414 | CASE constant_expression ':' statement
415 | DEFAULT ':' statement
420 : '{' '}' { $$
= new ASTNode
() }
421 |
'{' statement_list
'}' { $$
= $2 }
426 | declaration_list declaration
{ $$
= new Semicolon
($1, $2) }
431 | statement_list statement
{ $$
= new Semicolon
($1, $2) }
435 : ';' { $$
= new ASTNode
() }
436 | expression
';' { $$
= $1; }
440 : IF
'(' expression
')' statement
{ $$
= new IfThenElse
($3, $5); }
441 | IF
'(' expression
')' statement ELSE statement
442 { $$
= new IfThenElse
($3, $5, $7); }
443 /*| SWITCH '(' expression ')' statement*/
446 // Loop(body, init, precond, postcond, before, after)
448 : WHILE
'(' expression
')' statement
449 { $$
= new Loop
($5, 0, $3, 0, 0, 0); }
450 | DO statement WHILE
'(' expression
')' ';'
451 { $$
= new Loop
($2, 0, 0, $5, 0, 0); }
452 | FOR
'(' expression_statement expression_statement
')' statement
453 { $$
= new Loop
($6, $3, $4, 0, 0, 0); }
454 | FOR
'(' expression_statement expression_statement expression
')' statement
455 { $$
= new Loop
($7, $3, $4, 0, 0, $5); }
456 // scriptor compatibility
457 | FOR
'(' expression_statement expression_statement expression_statement
')' statement
458 { $$
= new Loop
($7, $3, $4, 0, 0, $5); }
462 : GOTO IDENTIFIER
';' { $$
= new Jump
($2); }
463 | CONTINUE
';' { $$
= new Continue
(); }
464 | BREAK
';' { $$
= new Break
(); }
465 | RETURN
';' { $$
= new Return
(0); }
466 | RETURN expression
';' { $$
= new Return
($2); }
470 : external_declaration
{ $$
= $1; $$
->parent
= root
; root
->list.push_back
($1); }
471 | translation_unit external_declaration
{ $$
= $2; $$
->parent
= root
; root
->list.push_back
($2); }
476 : function_definition
482 : declarator compound_statement
{ $$
= new Function
($1, $2) }
486 : PRAGMA IDENTIFIER NUMBER
{ $$
= new Pragma
($2, $3); }
487 | PRAGMA IDENTIFIER IDENTIFIER
{ $$
= new Pragma
($2, $3); }
488 | PRAGMA IDENTIFIER
{ $$
= new Pragma
($2, 0); }