[antlr-interest] Parse expression

Luis Gervaso luis.gervaso at gmail.com
Wed May 3 04:47:28 PDT 2006


Hello,

I hava a hasmap like this

5001 - 1.5
5002 - 2.5
...
600 - 3.5

and if user types

"500?" antlr evaluate 5001 + 5002 = 4

my treeparser is

{import java.util.Map;}
class CalcTreeWalker extends TreeParser;

expr [Map balance] returns [double r] { double a, b; r = 0; }
        : #(PLUS a=expr[balance] b=expr[balance] ) {r=a+b;}
        | #(MINUS a=expr[balance] b=expr[balance] ) {r=a-b;}
        | #(STAR a=expr[balance] b=expr[balance] ) {r=a*b;}
        | #(SLASH a=expr[balance] b=expr[balance] ) {r=a/b;}
        | i:NUM {r=(Double) balance.get(i.getText());}
        ;

I need exploit regular expression in order to evaluate

regards


--
-------------------------------------------
Luis Alberto Gervaso Martin
J2EE Architect & Instructor
C/ San Sebastian 1, 2ºB
Getafe (Madrid)
SPAIN
mobile: (+34) 627983344
luis.gervaso at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060503/15ae3c10/attachment.html


More information about the antlr-interest mailing list