-2

I have shift/reduce conflict in bison.

I checked the parser.output file:

State 0

0 $accept: . Prog $end

STRUCT  shift, and go to state 1

$default  reduce using rule 6 (Structs)

Prog        go to state 2
Structs     go to state 3
StructDec   go to state 4

I have the rules:

Prog    :   Structs Funcs {};
Structs :   StructDec Structs | {};
StructDec : STRUCT ID LB StrctMmLst RB SC{};

And Prog is the start symbole.

%start Prog

I assume the reason is the epsilon rule of structs. How can I resolve it without changing the meaning?

rici
  • 234,347
  • 28
  • 237
  • 341
SuzLy
  • 133
  • 1
  • 10
  • 1
    When you look at the bison `.output` file, try to focus on the states with parsing conflicts. You'll see a list of such states near the beginning of the report. It is very rare that the conflict is in the start state, which is probably the least useful state to examine. – rici Dec 04 '18 at 16:36
  • 1
    Also, the excerpt from the grammar does not shiw enough to see a parsing conflict. There is probably some interaction with `Funcs` (for example, if `Structs` and `Funcs` have a common element in their FIRST sets.) – rici Dec 04 '18 at 16:39
  • Thank you so much @rici ! I wasn't reading the output file the right way.. – SuzLy Dec 04 '18 at 16:50

1 Answers1

0

The solution actualy was to look at the beginning of the file. there you can see the numbers of the conflictiong states. The one I was looking at was not a conflict at all.

SuzLy
  • 133
  • 1
  • 10