%token NAME NUMBER LPAREN RPAREN EQUAL PLUS MINUS %token TIMES DIVIDE IF THEN ELSE /* associativity and precedence: in order of increasing precedence */ %nonassoc LOW /* dummy token to suggest shift on ELSE */ %nonassoc ELSE /* higher than LOW */ %nonassoc EQUAL %left PLUS MINUS %left TIMES DIVIDE %left UMINUS /* dummy token to use as precedence marker */ %% stmt : IF exp THEN stmt %prec LOW | IF exp THEN stmt ELSE stmt /* shift will be selected */ | /* other types of statements would come here */ ; exp : exp PLUS exp | exp MINUS exp | exp TIMES exp | exp DIVIDE exp | exp EQUAL exp | LPAREN exp RPAREN | MINUS exp %prec UMINUS /* this will force a reduce */ | NAME | NUMBER ; %%