CnewbieWannabePro
CnewbieWannabePro

Reputation: 130

Bison useless non-term

σI am trying to create a simple bison example. I have defined the operation's values from my .l file but when i try to do a -v check for conflicts, the expr is in no way connected to the stmt, therefore the bison recognizes just the 2 first things i wrote, even though i have a "expr SEMICOLON" in the beginning of the stmt. I am also getting a reduce/reduce conflict in state 0. Any ideas?

program: state
    |;

state: expr SEMICOLON
  | BREAK SEMICOLON
  | CONTINUE SEMICOLON 
  |;

expr: expr "+" expr
| expr "-" expr
| expr "*" expr
| expr "/" expr
| expr "%" expr
;

Upvotes: 1

Views: 60

Answers (1)

sepp2k
sepp2k

Reputation: 370377

All the cases for expr are recursive, so there's no way for expr to ever match any input. You need a base case (NUM and/or ID for example).

The reduce/reduce conflict is caused by the fact that both program and stmt have an empty case. So since stmt is also one of the cases for program, there are two possible paths to derive the empty string from program (program -> stmt -> "" and program -> ""). So you need to remove one of the empty cases.

Upvotes: 1

Related Questions