Consider the following ANTLR 4 grammar:
grammar Test;
start: e EOF;
e : e '+' e #op
| NUMBER #atom
;
NUMBER: [0-9]+;
Based on the disambiguation rules of ANTLR, in this case binary operators being left associative, the result of parsing the string 1+2+3
is ((1+2)+3). But there is another parse tree possible, namely (1+(2+3)), if you don't consider the ANTLR's default disambiguation rule.
Is there a way to get both parse trees in ANTLR? Or at least enabling a flag or something, so that it tells me that there was another parse tree and possibly print it?
Update I understand that in ANTLR, this grammar is unambiguous, because binary operators are always left-associative, but I couldn't come up with another example. My whole point is that I'd like to get an warning (or something similar) whenever ANTLR tries to resolve the ambiguity. For example, in good old Yacc (Bison), if I have the same grammar:
s : e
;
e : e '+' e
| NUMBER
;
when generating the parser, I get the warning State 6 conflicts: 1 shift/reduce
.