[antlr-interest] Source positions for imaginary tokens

Mike Lischke mike at lischke-online.de
Wed Sep 12 23:53:31 PDT 2012


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