[antlr-interest] Source positions for imaginary tokens

Jim Idle jimi at temporal-wave.com
Thu Sep 13 09:18:34 PDT 2012


Just use $token->type = ID;

That's all I do - the type field will never change.

At code generation time, all I have as some text in the string template,
that I must use to create the code text. I don't know what type of object
it is and neither does any other target; they use overloaded methods - I
don't have that luxury.

Jim

> -----Original Message-----
> From: Mike Lischke [mailto:mike at lischke-online.de]
> Sent: Wednesday, September 12, 2012 11:54 PM
> To: Jim Idle
> Cc: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Source positions for imaginary tokens
>
>
> Hey Jim,
>
> > Sure - I can make it be either of those calls, but not both at once.
> I
> > have no context at code generation time that can tell me which one to
> generate.
>
> So you say, you don't know at this time what type $kw in the ID[$kw]
> expression is? Absolutely no way to determine if that is a string or a
> token reference? That's odd.
>
> > If I change it to this, then all the people that want it to be the
> > other way, will claim that they have found a bug too. It only works
> in
> > Java because the Java compiler can see what the argument types are,
> > and can therefore call the "correct" method.
>
> I understand your restrictions, but find this situation all but
> pleasant (and I'm not alone I'm afraid).
>
> > However, it is much simpler to just use code to operate on the token
> > directly. Even before that, you should consider whether you need to
> > change something about the token because a later stage MUST receive a
> > different token, or whether you just think that you WANT it to.
>
>
> In the keyword case it is just so that I need only one (very common)
> token type but want to retain the token text for later processing. It's
> unfortunate that there is no general solution for the frequently
> encountered keywords-as-identifier problem.
>
> Anyway, Jim, thanks for patience and time!
>
> Mike
> --
> www.soft-gems.net
>


More information about the antlr-interest mailing list