antlr 3 ambiguity

Posted by tcris on Stack Overflow See other posts from Stack Overflow or by tcris
Published on 2010-05-15T17:56:50Z Indexed on 2010/05/15 18:04 UTC
Read the original article Hit count: 149

Filed under:
|

Hello, I try to write some simple rules and I get this ambiguity

rule: field1 field2; //ambiguity between nsf1 and nsf2 even if I use lookahead k=4

field1: nsf1 | whatever1...;
field2: nsf2 | whatever2...;

nsf1: 'N' 'S' 'F' '1'; //meaning: no such field 1
nsf2: 'N' 'S' 'F' '2'; //meaning: no such field 2
  1. I understand the ambiguity, but I don't understand why lookahead doesn't solve this.

  2. I have a simple solution but I don't like it:

    rule: (nsf1 (nsf2 | whatever2)) | (whatever1 (nsf2 | whatever2));

Does anybody have a more elegant solution?

Thanks a lot, Chris

© Stack Overflow or respective owner

Related posts about antlr

Related posts about antlr3