[antlr-interest] antlr - sub ast tree
Alessandro Leonardi
alessandro1.leonardi at telecomitalia.it
Fri Apr 20 07:53:49 PDT 2007
Hi,
I'm working about an existing antlr grammar.
I'm using java.
In the Tree Parser Class are defined 2 method:
expr and exprs
class ExpressionTreeWalker extends TreeParser;
.
expr returns [double r]
.
strs returns [String r]
.
Expr implements the ast evalutation on numeric operators, Strs on string
operators.
Some AST subtree nodes should be calculated by expr and some others by strs
but if I use this syntax,
CommonAST parseTree = (CommonAST) this.getAST();
ExpressionTreeWalker walker = new ExpressionTreeWalker();
String r = walker.expr(parseTree);
all tree will be evaluated by expr method.
How is possible to force the ast evaluation to use strs to traverse a
particular subtree?
Example:
..
relExpression:
expr ^EQ expr
.
tokens {
..
EQ:"="
..
}
class ExpressionTreeWalker extends TreeParser;
.
expr returns [double r]
{ double a,b; r=0; String str,str1,str2;
}
#EQ (a=expr b=expr) {
// number relation
}
.
strs returns [double r]
{ String a,b; r=0; String str,str1,str2;
}
#EQ (a= strs b= strs) {
// strings relation
}
.
// java ast evaluation
CommonAST parseTree = (CommonAST) this.getAST();
ExpressionTreeWalker walker = new ExpressionTreeWalker();
String r = walker.expr(parseTree);
How is possible to force the relExpression evaluation using the strs.EQ
instead expr.EQ ? ( for example if a code variable indicated this )
I hope to be clear,
Thanks a lot!
Bye
Alessandro
--------------------------------------------------------------------
CONFIDENTIALITY NOTICE
This message and its attachments are addressed solely to the persons above and may contain confidential information. If you have received the message in error, be informed that any use of the content hereof is prohibited. Please return it immediately to the sender and delete the message. Should you have any questions, please contact us by replying to webmaster at telecomitalia.it.
Thank you
www.telecomitalia.it
--------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20070420/37fb67af/attachment-0001.html
More information about the antlr-interest
mailing list