[antlr-interest] Antlrworks bug?

Jim Idle jimi at temporal-wave.com
Wed Nov 21 10:08:37 PST 2007


Think through your example below again, they are logically entirely different, but the mis-interpretation is why I think that the literals in the parser is actually causing more trouble than help, especially to people new to it. I advise that nobody uses these until they are completely in command of the system.

Using a literal deinfes a lexer token as being the literal you use. So: 'X'+ means define a token for the text 'X' and it can repeat 1..n times. Whereas your lexer rule is saying that it is a token called Z and this SINGLE TOKEN can be 1..n 'X' characters.

So, don't use the literals in your parser as it is confusing to people unless they are already understand it (you can't get there from here ;-).

Jim  

> -----Original Message-----
> From: Steve Bennett [mailto:stevagewp at gmail.com]
> Sent: Wednesday, November 21, 2007 4:53 AM
> To: Johannes Luber
> Cc: antlr-interest Interest
> Subject: Re: [antlr-interest] Antlrworks bug?
> 
> On 11/21/07, Johannes Luber <jaluber at gmx.de> wrote:
> > It's no bug but a feature. ;) Joking aside, you can't do closures with
> > ranges in parser rules. The correct way is the one below.
> 
> So many gotchas :( And nowhere to look up a set of rules of what works
> in what type of grammar. The "definitive reference" is neither
> definitive, nor a reference...*
> 
> I also only realised today that there is a difference between:
> 
> x: 'X'+;
> 
> and:
> ---
> x: Z;
> Z: 'X'+;
> ---
> 
> (logically imho they should behave the same, and x: ('X')+; should
> give the behaviour of the first one)
> 
> I think I was a happier man when I thought you couldn't use literals
> in parser rules at all.
> 
> Steve
> * Which isn't to say that it isn't extremely helpful. But it doesn't
> seem to cover everything, and it isn't arranged in a way which is
> convenient for quickly looking stuff up.




More information about the antlr-interest mailing list