0

I am trying to write a parser with Bison. I get the warning:

 warning: 5 shift/reduce conflicts [-Wconflicts-sr]

My rules:

%%
Prog    :   F {};
F   :    {};
F   :   D F {};
D   :   R ID LP Fr RP LB Ss RB {};
R   :   T {};
R   :   VOID {};
Fr  :    {};
Fr  :   Fl {};
Fl  :   Fd COM Fl1 {};
Fl1 :   | Fl1 Fd COM {};
Fd  :   T ID Fd1{};
Fd1 :   LB NUM BM RB{};
BM  :   B | {};
Ss  :   S | Ss S {};
S   :   LB Ss RB {};
S   :   T ID SC {};
S   :   T ID ASGN E SC {};
S   :   T ID LB NUM RB SC {};
S   :   T ID LB NUM B RB SC {};
S   :   ID ASGN E SC {};
S   :   ID LB E RB ASGN E SC {};
S   :   C SC {};
S   :   RET SC {};
S   :   RET E SC {};
S   :   IF LP E RP S {};
S   :   WHILE LP El RP S {};
S   :   BREAK SC {};
C       :   ID LP ElM RP {};
ElM :   El | {};
El  :   E El1{};
El1 :   | COM El {};
T   :   INT | BYTE | BOOL {};
E       :   LP E RP | ID LB E RP |ID | C | NUM | NUM B | STR | TRUE | FALSE |   NOT E | E Op E {};
Op      :   AND | OR | RLP | BNP {};
%%

How can I know where are the conflicts? I've tried combining rules, but the number of conflicts had never changed. What can be the reason?

user207421
  • 305,947
  • 44
  • 307
  • 483
SuzLy
  • 133
  • 1
  • 10
  • The conflicts are in your rule for expressions, or at least some of them are. I'd start there. Hyperabbreviating does not make your code easy to read. – rici May 19 '18 at 14:07

1 Answers1

0

The -v option to bison causes bison to produce a y.output file (actually called whatever.output where 'whatever' is the base name of your input file, unless you're using yacc compatibility).

The y.output file contains a full summary of the parser generated from your grammar -- all the rules, and all the parser states, and all the actions in the states. It also identifies which states contain all the conflicts and how those conflicts were resolved to produce a parser.

Chris Dodd
  • 119,907
  • 13
  • 134
  • 226