[antlr-interest] Best practices in making ASTs

Aaron Armstrong ae.armstrong at gmail.com
Wed Feb 6 11:28:05 PST 2008


I'm trying to make a non-flat AST from the java grammar given on the
antlr.org website. All I'm wanting is a node with the grammar rule, then all
its children being parts in that rule.  For example, importDeclaration:
importDeclaration: 'import' 'static'? Identifier ('.' Identifier)* ('.'
'*')? ';' ;
I just map it to the current grammar via -> and add ^:
importDeclaration: 'import' 'static'? Identifier ('.' Identifier)* ('.'
'*')? ';' -> ^('import' 'static'? Identifier ('.' Identifier)* ('.' '*')?
';');
The problem is when the parser recognizes import java.io.*;, the AST grammar
gets to the java.io and exits prematurely on .* because it doesn't match '.'
Identifier.  Essentially, it's not performing lookahead in the AST output
grammar.  Is there a good workaround to this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080206/ecd0e936/attachment.html 


More information about the antlr-interest mailing list