[antlr-interest] C codegen change request: Expose TokenNames array
Brent Yates
brent.yates at gmail.com
Sun Jun 22 11:59:24 PDT 2008
Jim,
I would like to request a minor addition to the C codegen string template.
I would like the generated parser code to expose the TokenNames array.
Currently this array can only be accessed from actions in the rule code. I
would like to be able to get to it via a straight C function call external
to a parser instance. The reason I need this is for diagnostic display. In
addition to retrieving a pointer to the array, I need to know the size of
the array.
Currently I modify the C.stg file and add the following lines:
This block is placed just after the context structure generation in the
header section (around line 692).
<if(PARSER)>
// Returns a pointer to the TokenNames array
ANTLR3_API pANTLR3_UINT8* <name>TokenNamesArray();
// Returns the number of elements in the TokenNames array
ANTLR3_API ANTLR3_UINT32 <name>TokenNamesArraySize();
<endif>
This block is placed just after the getTokenNames function code (around line
1395).
<if(PARSER)>
// Returns a pointer to the TokenNames array
pANTLR3_UINT8* <name>TokenNamesArray()
{
return(<grammar.composite.rootGrammar.recognizerName>TokenNames);
}
// Returns the number of elements in the TokenNames array
ANTLR3_UINT32 <name>TokenNamesArraySize()
{
return(<length(tokenNames)>+4);
}
<endif>
Thanks!
Brent Yates
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080622/4b355d3e/attachment.html
More information about the antlr-interest
mailing list