forked from thborges/robcmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrob.y
46 lines (34 loc) · 819 Bytes
/
rob.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
%{
#include "node.h"
#include <stdio.h>
%}
%token TOK_MAGNET TOK_ROTATE TOK_WAIT_BUTTON_PRESS TOK_INTEIRO
%union {
int nint;
Node *node;
Stmts *stmt;
}
%type <node> number stmt
%type <stmt> stmts
%type <nint> TOK_INTEIRO
%start programa
%%
programa : stmts { Program p; p.generate($1); }
;
stmts : stmts stmt { $$->append($2); }
| stmt { $$ = new Stmts($1); }
;
stmt : TOK_MAGNET number';' { $$ = MagnetCommand($2); }
| TOK_ROTATE number number';' { $$ = RotateCommand($2, $3); }
| TOK_WAIT_BUTTON_PRESS';' { $$ = WaitButtonPressCommand(); }
;
number : TOK_INTEIRO { $$ = new Int16($1); }
;
%%
void yyerror(const char *s){
fprintf(stderr, "%s:%d: error: %s %s\n", build_filename, yylineno, s, yytext);
exit(1);
}
extern "C" int yywrap() {
return 1;
}