tags:

views:

29

answers:

1
+1  Q: 

antlr 3 ambiguity

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

A: 

I couldn't reproduce your problem, but all I could do was guess what the rules for 'whatever1' and 'whatever2' were. Can you post a more complete grammar?

However, there's nothing in the grammar that couldn't be done entirely with lexer token rather than parser rules. Try capitalizing all of the rule names to turn them into lexer token and see if that helps.

Barry Brown
false problem indeed, there was a mistake in my description :-(thanks
tcris