[antlr-interest] AST Question
massimiliano.masi at gmail.com
massimiliano.masi at gmail.com
Fri May 20 12:54:50 PDT 2011
Hi,
On Fri, May 20, 2011 at 10:55 AM, Bart Kiers <bkiers at gmail.com> wrote:
> targetsExpr
> : category ('CAND' targetsExpr)* -> ^('CAND' category targetsExpr*)
> ;
>
> is incorrect. You're always using `CAND` in your rewrite rule but that rule
> could just match `category` only.
> You'll probably want to do:
>
> targetsExpr
> : category ('CAND'^ targetsExpr)*
> ;
>
Thank you for your answer! It works now! But I've another question now.
When I traverse the tree using this function (is there an example to
have a visitor
created by antlr?)
public void visitTree(CommonTree t) throws Exception {
if ( t != null ) {
for ( int i = 0; i < t.getChildCount(); i++ ) {
// System.out.println(t.getChild(i).toString() + " type " +
t.getType() + " child type " + t.getChild(i).getType());
visitNode(t);
visitTree((CommonTree)t.getChild(i));
}
}
}
in the visitNode() I have the same token type as for the children. I
explain better:
If I have something like:
FAC->child(1),child(2), child(3)
the visitNode(t) is called 3 times with the same token type!
You can see the grammar here: http://www.mascanc.net/~max/xacml3.g
Thank you and best regards,
Massimiliano
--
Massimiliano Masi
http://www.mascanc.net/~max
More information about the antlr-interest
mailing list