0
votes

When I want to create a parser out of my grammar ANTLR gives me an error about a non-LL(*) conform content. I do understand that this means that there must be a point where the parser can't distinguish between two or more rules but what I don't understand is what ANTLR means by saying that this ambiguity is reachable from (for example) 'alts 1,2'.
Is there a way to interpret these numbers to actually find the particular input which causes this ambiguity so that I know what I have to fix? Because I find it really difficult to look at my grammar again and find out what causes this issue...

Best regards Raven

2
It will be easier for people to guide you if you include your actual ANTLR grammar (or relevant excerpts from it) in the question. - 500 - Internal Server Error
I'm actually not referring to an concrete example...It's meant as a general question (My grammar and even the relevant excerpts would be hundreds of lines. Therefore I wanted to understand these messages by myself) - Raven
Doesn't the ambiguity error you are getting refer to a particular production that you could post? Generally, those types of errors refer to productions like 'HELLO' 'MOM' | 'GOODBYE' DAD' | 'HELLO' 'DAD' where an LL(1) parser can't distinguish between alternatives 1 and 3 just by seeing HELLO. - 500 - Internal Server Error
Well that's actually exactly the answer I was looking for... Never understood that the listed alternatives refer to the actual rule itself... Thank you! - Raven

2 Answers

1
votes

The message will state the line in the grammar file where the problem occured. 'alts 1,2' means ANTLR found ways two ways to match the input which differ in how to continue at given location, so it cannot decide which way to take. Examples of what is meant by alternatives 1 and 2:

rule1:
  ( choice1  // alternative 1
  | choice2  // alternative 2
  )
  ;

rule2:
  choice?  // alternative 1: go into choice rule
           // alternative 2: skip over choice rule
  ;

rule3:
  choice*  // alternative 1: go into choice rule (either first time or repeatedly)
           // alternative 2: skip over choice rule (either skip it or don't repeat anymore)
  ;

rule4:
  choice+  // alternative 1: repeat once more
           // alternative 2: don't repeat anymore
  ;
0
votes

If there is someone who still has some difficulties with these error-messages (like me) then this method could be quite useful for you.
It describes a way to visualize the syntax tree (quite similar to the build-in Xtext-syntaxGraph but this one highlights the actual part Antlr is complaining about.)

Best regards Raven