cwbaker / lalr

LALR(1) parser for C++
MIT License
76 stars 10 forks source link

Example that bison/yacc reports reduce/reduce conflict but lalr doesn't #52

Open mingodad opened 1 year ago

mingodad commented 1 year ago

From the bison manual https://www.gnu.org/software/bison/manual/bison.html#Mysterious-Conflicts lalr doesn't report any conflict.

mysterious_reduce_reduce {
%whitespace "[ \t\r\n]*" ;

def: param_spec return_spec ',';
param_spec:
  type
| name_list ':' type
;

return_spec:
  type
| name ':' type
;

type: 'id';

name: 'id';
name_list:
  name
| name ',' name_list
;
}

input:

id id

Playground lexer dump:

=line:column:type:index:identifier:lexeme:value
1:1:1:10:[name]:[id]:[id]
1:4:1:10:[name]:[id]:[id]
1:6:1:7:[comma_terminal]:[,]:[,]
=line:column:type:index:identifier:lexeme:value
1:1:1:10:[name]:[id]:[id]
1:4:1:10:[name]:[id]:[id]
1:6:1:7:[comma_terminal]:[,]:[,]

Playground parse tree:

def
 |param_spec
 | |name -> id
 |return_spec
 | |name -> id
 |comma_terminal -> ,