[antlr-interest] How to set text in a tree node?
bjsp123
bjsp123 at yahoo.com
Tue Nov 4 05:26:24 PST 2003
Hi,
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++:
strct
: "struct"!
j:identifier!
LCURLY! member_list RCURLY!
{ #strct = #([STRCT, j_AST->getText()], #strct); }
;
This is a horrible solution which I can't imagine actually putting in
production! Surely there must be some workaround? I just want my
artificial node to somehow take the text of the identifier, so that I
can build a reasonably efficient tree.
Benjamin
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list