Can anyone help me understand what makes ANTLR not report an issue with the ambiguity in this grammar?
https://github.com/NASA-SW-VnV/fret/blob/master/fret-electron/support/NuSMVParser/NuSMV.g4#L61-L78
The rules in simpleExpr and ltlExpr are duplicated in such a way that there are always two alternative paths to build anything with an and, or, xor, implies, equiv, not operator applied to it, or some parenthesized expressions.
When I run ANTLR on it, I would expect to see a warning but I get nothing (meaning a parser and a lexer are produced).
Since ANTLR matches parser rule in a first-come-first-serve manner, the first rule that matches "wins" (the parser doesn't care that certain input can be parsed in multiple ways).
To display the ambiguity, you could attach a custom error listener and override its
reportAmbiguitymethod and set the prediction mode toPredictionMode.LL_EXACT_AMBIG_DETECTION.Take the following grammar where the
print_statement_1andprint_statement_2alternatives fromstatementare ambiguous:and if you run the following code:
the following will be printed: