[antlr-interest] Target Language .stg Files - Token Names

Justin Holewinski shawmishrak at gmail.com
Tue Jun 9 06:49:16 PDT 2009


Thanks for the suggestion.  Unfortunately, this option does not appear to
give any additional information regarding the attributes of <token>, if any.


Thanks,

Justin Holewinski


On Mon, Jun 8, 2009 at 6:23 PM, Johannes Luber <JALuber at gmx.de> 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?
>
> ANTLR supports the option -XdbgST (capitilization is important - ANTLR
> silently swallows errors there) which adds the template names to the output.
> The most difficult thing is to find the right place as token may be
> constructed like "<rule>suffix".
>
> >
> > 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.
>
> The best way I know would be to use -XdbgST and to check all called
> templates. It may not solve the original problem but at least you know where
> to look.
>
> Johannes
> >
> >
> > Thanks,
> >
> > Justin Holewinski
>
> --
> GMX FreeDSL mit DSL 6.000 Flatrate und Telefonanschluss nur 17,95
> Euro/mtl.!
> http://dslspecial.gmx.de/freedsl-aktionspreis/?ac=OM.AD.PD003K11308T4569a
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090609/fbb95dd3/attachment.html 


More information about the antlr-interest mailing list