%{ #include int yylex(); int yyerror(const char* p) { fprintf(stderr, p); } %} %define parse.trace %union { char* sym; float num; } %token ID %token STOP %token NUM %token STRING %token INDENT DEDENT %token IF ELIF ELSE %right GETS %left '+' '-' %left '/' '*' %left MAPS %% program: statements | statements statement; statements: statements statement STOP | statements STOP | // null production ; statement: assignment | funcall | conditional; assignment: ID GETS expr; assignments: assignments assignment STOP | // null production; expr: funcdef | funcall | objdef | expr '+' expr | expr '-' expr | expr '*' expr | expr '/' expr | '(' expr ')' | ID | NUM | STRING; funcdef: param MAPS expr | param MAPS block; param: ID | '_' | // null production; funcall: ID '(' exprlist ')' exprlist: exprlist ',' expr | expr | // null production; conditional: IF expr block elifs | IF expr block elifs ELSE block; elifs: ELIF expr block elifs| // null production; objdef: '{' block_assignments '}' | '{' '}' block: STOP INDENT statement statements DEDENT block_assignments: STOP INDENT assignments DEDENT %%