[antlr-interest] Target Language .stg Files - Token Names
Mark Wright
markwright at internode.on.net
Sat Jun 13 03:34:41 PDT 2009
Maybe an AttributeRenderer might help:
http://www.antlr.org/wiki/display/ST/Object+rendering
Thanks, Mark
On Mon, 8 Jun 2009 17:36:46 -0400
Justin Holewinski <shawmishrak at gmail.com> wrote:
> I've been working on a C++ (STL + Boost) target for Antlr 3, and I'm
> struggling with some StringTemplate semantics. Specifically, when
> generating code for matching tokens, the <token> template will
> sometimes refer to a textual token name (e.g. ID) and other times it
> will refer to a constant, the token identifier (e.g. 33). Is there a
> way to determine, within a StringTemplate rule, which of these
> representations is used?
>
> I would like to generate code like:
>
> match(MyParser::TOKEN_ID);
>
> for token names, and
>
> match(33);
>
> for token constants, so I would like to do something like:
>
> <if(token.isNumber)>
> match(<token>);
> <else>
> match(MyParser::TOKEN_<token>);
> <endif>
>
> but how to do this is eluding me.
>
>
> Currently, I am forced to use preprocessor magic to get by:
>
> #undef ID
> #define ID MyParser::TOKEN_ID
> ...
>
> which I hate to do for multiple reasons.
>
>
> On a side note, is there any documentation of which attributes are
> avilable for variables in target language .stg files? For instance,
> what attributes are available on a <rule>? All of the information I
> find comes from deciphering the other .stg files.
>
>
> Thanks,
>
> Justin Holewinski
--
More information about the antlr-interest
mailing list