rendered paste body%{
#include <stdio.h>
#include <string.h>
#define YYSTYPE char *
void yyerror(const char *str) {
fprintf(stderr,"error: %s\n",str);
return;
}
int yywrap() {
return 1;
}
main() {
yyparse();
}
%}
%token NUMBER WORD OPEN_BRACKET CLOSE_BRACKET OPEN_PAREN CLOSE_PAREN COMMA ASSIGNED_TO SEMI_COLON PLUS MINUS DIVIDE MULTIPLY
%%
statement : /* nothing here */
| statement WORD ASSIGNED_TO exp SEMI_COLON { printf("%s", $5); }
;
exp : expression OPEN_BRACKET expression CLOSE_BRACKET
| OPEN_BRACKET expression CLOSE_BRACKET expression
| OPEN_BRACKET expression CLOSE_BRACKET
| expression
;
expression : low_lvl_exp
| low_lvl_exp PLUS expression
| low_lvl_exp MINUS expression
| low_lvl_exp MULTIPLY expression
| low_lvl_exp DIVIDE expression
;
low_lvl_exp : NUMBER operator NUMBER
| WORD operator WORD
| WORD operator NUMBER
| NUMBER operator WORD
| WORD
| NUMBER
;
operator : PLUS
| MINUS
| MULTIPLY
| DIVIDE
;
%%