[antlr-interest] Token type as string

Miguel Ping miguel.ping at gmail.com
Thu May 3 14:55:55 PDT 2007


edit: Sorry for the 2x reply, I just need to lose the habit of not replying
to the mailing list

Err, what version of antlr are you using? I'm guessing v2, I never used it.
I use v3. In v3 there is no special switch or something.

Anyway, I guess there should be a place somewhere where the token <> int is
defined. Try peeking inside the .txt or the .smap. I don't know the v2
generation procedure, but it should be similar to v3. If you run outta luck,
just ask in the forum, I guess some v2 user should help you out.

On 5/3/07, Adrian Herscu <bmf1972 at fastmail.fm> wrote:
>
> Hi Miguel, thanks for your fast reply.
>
> I looked into the generated files directory and only file types see
> there are expanded*.g, *.smap, *.txt and of course *.java.
> Is there some switch to generate them?
> Adrian.
>
>
> Miguel Ping wrote:
> > Hi,
> >
> > There is a file with the grammar name and .tokens extension
> > (MyGrammar.tokens) that contains correspondence between numbers and
> > strings. This file is created by antlr generator. Take a look, it
> > should suit your needs.
> >
> > On 5/3/07, Adrian Herscu
> > <bmf1972 at fastmail.fm> wrote:
> >> Hi all,
> >>
> >> I would like to write an XSL template to transform my AST.
> >> I tried to serialize the AST as XML and I am getting something like:
> >>
> >> <antlr.CommonAST text="compilation-unit" type="4">
> >>    <antlr.CommonAST text="package" type="15">
> >>      ...
> >>    </antlr.CommonAST>
> >> </antlr.CommonAST>
> >>
> >> In order to apply an XSL transformation using matching templates, I am
> >> transforming the above into:
> >>
> >> <compilation-unit>
> >>    <package>
> >>      ...
> >>    </package>
> >> </compilation-unit>
> >>
> >> then I can bind XSL templates such as match="/compilation-unit",
> >> match="package", etc.
> >>
> >> The problem is with AST nodes that have text content which cannot
> >> function as XML tags - for example:
> >>
> >> <CommonAST text="123" type="14" />
> >>
> >> In this case <123 /> is an illegal XML tag.
> >> type="14" means that there is some token assigned the identifier 14.
> >>
> >> If there would be some easy way to change the token type identifiers to
> >> strings or to add a string field associated with the token type then it
> >> would solve my problem really quick.
> >>
> >> Is there such a thing? A better approach?
> >>
> >> Adrian.
> >>
> >>
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070503/e6de59d8/attachment.html 


More information about the antlr-interest mailing list