[antlr-interest] How to set text in a tree node?

Ric Klaren klaren at cs.utwente.nl
Tue Nov 4 05:44:09 PST 2003


Hi,

On Tue, Nov 04, 2003 at 01:26:24PM -0000, bjsp123 wrote:
>   When I'm parsing a C-like struct declaration, I'd like to use a 
> rule like this:
> 
> strct
>   :   "struct"!
>       j:identifier!
>       LCURLY! member_list RCURLY!
>       { #strct = #([STRCT, #j->getText()], #strct); }
>   ;
> 
> This should produce a node whose type is STRCT and whose text is the 
> text found in the identifier, ie the structure name.  But, it doesn't 
> work because the #j is not handled correctly -- when generating C++, 
> it emits a simple 'j', whereas the variable is actually 
> called 'j_AST'.  The following works for C++:

Which antlr version is this ? Could you try a development snapshot from
http://wwwhome.cs.utwente.nl/~klaren/antlr/ and see if the problem
persists?

Longshot: try turning off AST generation for the complete rule and remove
the ! from the tokens/references in the rule. Something like this:

> strct !
>   :   "struct"
>       j:identifier
>       LCURLY m:member_list RCURLY
>       { #strct = #([STRCT, #j->getText()], #m); }
>   ;

Cheers,

Ric
--
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893722  ----
-----+++++*****************************************************+++++++++-------
  Wit is cultured insolence. --- Aristotle


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list