[antlr-interest] Q: How to understand 'multiple alternatives'?

Johannes Luber jaluber at gmx.de
Sat Aug 16 09:26:38 PDT 2008


Austin Hastings schrieb:
> Howy,
> 
> I'm parsing a C-like language, and I'm getting this kind of warning:
> 
> warning(200): perl6/hlasm/Hlasm.g3:245:4: Decision can match input such 
> as "'&'" using multiple alternatives: 1, 2
> As a result, alternative(s) 2 were disabled for that input
> 
> In several places. In fact, the '&' (and several other characters) can 
> have different roles to play in the language. In this case, & can either 
> be a bitwise and, or an address operator.
> 
> However -- and this is what confuses me -- I can't seem to see what 
> antlr is griping about. According to me, and expression like
> 
> a & b
> 
> should not be confusable with
> 
> &foo
> 
> so I'm wondering why antlr seems to feel that there are different 
> alternatives that can parse the &.
> 
> Obviously, either there's a problem with antlr or a problem with my 
> grammar. I'd like it to be with my grammar, since I can likely fix that.
> 
> So my question is, how do I understand what the multiple alternatives 
> are, here? I tried dumping the nfa/dfas, to little avail.
> 
> Recommendations, advice?
> 
> =Austin
> 
Did you try ANTLRworks? Use the "check grammar" option look for rules 
highlighted with red. Then look at syntax diagrams and decipher the 
different paths a grammar can take to get from point A to point B.

Johannes


More information about the antlr-interest mailing list