[antlr-interest] Generic AST tree parser
Stefan Bucur
stefan.bucur at gmail.com
Wed Mar 19 06:39:51 PDT 2008
Hello!
I'm trying to build a tree grammar that would accept any AST generated
by an ANTLR grammar, and display it on the screen. However, my code
fails to show elements below the first level, and it shows only the
root elements in the AST. The tree grammar looks like:
start
: (syntaxTree[0])*
;
syntaxTree [int level]
@init {
int nextLevel = level + 1;
}
: ^(node[$level] (syntaxTree[nextLevel])* ) // Accept a subtree...
| node[$level] // ...or a leaf node
;
node [int level]
: token=. { System.out.println($level + " : " + $token.text); } //
Accept any token
;
catch [Exception e] { e.printStackTrace(); }
Do you have any idea what could be wrong? :-/
Thanks!
Stefan Bucur
More information about the antlr-interest
mailing list