[antlr-interest] question about V3 AST rewriting ?
Charlie Yang
Cyang at infobal.com
Fri Aug 24 12:33:23 PDT 2007
Hi, I have problem to find a way to rewrite AST when repeated subrules
occured.
The example I found online is:
'<html>' html_header html_body '</html>' -> ^('doc' html_header
html_body);
It works fine, however, when I try to implement others, say Java1.5 for V3
Q1: Given Grammar like this:
type : Identifier (typeArguments)? ('.' Identifier
(typeArguments)? )* ('[' ']')*
both "Identifier" and "typeArguments" occurred multi-times, how can I bring
it back in AST like
->^(TYPE Identifier1 typeArguments1 Identifier2? typeArguments2? ...)
Q2:And second question, given rule like below:
primitiveType
: 'boolean'
| 'char'
| 'byte'
| 'short'
| 'int'
It the an easy way to rewrite AST like ^(PRIMITIVE 'boolean'|'char'|....)
rather than:
: 'boolean' ->^(PRIMITIVE 'boolean')
| 'char' ->^(PRIMITIVE 'char')
...
Now I'm so missing old style grammar as 2.7.5 which at least I know how to
fully control the AST. Anywhere I can find a detail instruction about how to
rewrite AST for V3?
More information about the antlr-interest
mailing list