CF_KEYWORDS(FUNCTION, FILTER, PRINTDEBUG, INT, PRINT, CONST, VAR, PUTS, DIE, IF)
%type <x> term
+%type <x> block
%type <x> cmds
CF_GRAMMAR
}
;
+block:
+ term ';' {
+ $$=$1;
+ }
+ | '{' cmds '}' {
+ $$=$2;
+ }
+ ;
+
term:
/* EMPTY */ {
$$ = NULL;
$$->arg1 = $1;
$$->arg2 = $3;
}
- | IF '(' term ')' '{' cmds '}' {
- $$ = f_new_inst();
- $$->code = '?';
- $$->arg1 = $3;
- $$->arg2 = $6;
- }
- | IF '(' term ')' term {
+ | IF '(' term ')' block {
$$ = f_new_inst();
$$->code = '?';
$$->arg1 = $3;
printf( "New variable\n" );
$$ = NULL;
}
+ | SYM {
+ $$ = f_new_inst();
+ switch ($1->class) {
+ case SYM_VARIABLE_INT:
+ $$->code = 'i';
+ $$->arg1 = &($1->aux);
+ break;
+ default:
+ cf_error("Can not use this class of symbol as variable" );
+ }
+ }
| VAR '(' SYM ')' {
$$ = f_new_inst();
switch ($3->class) {
cf_error("Can not use this class of symbol as variable" );
}
}
+ | NUM {
+ $$ = f_new_inst();
+ $$->code = 'c';
+ $$->arg1 = $1
+ }
| CONST '(' expr ')' {
$$ = f_new_inst();
$$->code = 'c';