[antlr-interest] Token type as string

Adrian Herscu bmf1972 at fastmail.fm
Thu May 3 09:30:36 PDT 2007


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.
>>
>>
> 



More information about the antlr-interest mailing list