[antlr-interest] Interp Class
mblp at mega.ist.utl.pt
mblp at mega.ist.utl.pt
Fri Mar 30 06:29:56 PDT 2007
never used the Interp, I print my trees with something like this
(taken from antlr docs)
public static void printTree(CommonTree tree, int indent) {
if (tree != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < indent; i++)
sb = sb.append(" ");
for (int i = 0; i < tree.getChildCount(); i++) {
System.out.println(sb.toString() + tree.getChild(i).toString());
printTree((CommonTree) tree.getChild(i), indent + 1);
}
}
}
Also, the docs for antlr v3 use the '^^' operator
(http://www.antlr.org/wiki/display/ANTLR3/Tree+construction) :
additiveExpression
: multiplicativeExpression (('+'^^ | '-'^^) multiplicativeExpression)*
;
Hope it helps
On 3/30/07, Fırat KÜÇÜK <firatkucuk at gmail.com> wrote:
> any idea?
>
>
> 2007/3/29, Fırat KÜÇÜK <firatkucuk at gmail.com>:
> > Hi,
> >
> > i send a sample post to antlr-dev list. But i didn't receive a response.
> >
> > -------------------------------------------
> >
> > There is an Interp class in org.antlr.tool package.
> > It generates an AST according to the parser grammer.
> > But ignores automatic tree generation statements.
> >
> > my sample calculator grammar is:
> >
> > start : (operationSecond (EOL operationSecond)*
> EOL?)?;
> > operationSecond : operationFirst ((PLUS^ | MINUS^) operationFirst)* ;
> > operationFirst : NUMBER ((ASTERISK^ | SLASH^) NUMBER)*;
> >
> > for instance : 1 + 56 + 3 * 2
> >
> > Interp generates:
> >
> > (<grammar HesapMakinesi> (start (operationSecond (operationFirst 1) +
> > (operationFirst 56) + (operationFirst 3 * 2))))
> >
> > but i want:
> >
> > (+ (+ 1 56) (* 3 2))
> >
> > any solution?
> >
> >
>
>
> --
> Öğr. Gör. Fırat KÜÇÜK
> ADAMYO Distance Learning
> SAKARYA University / TURKEY
>
More information about the antlr-interest
mailing list