[antlr-interest] How to create binary AST with multiple operators?

Maciej Pilichowski bluedzins at op.pl
Thu Aug 9 14:30:26 PDT 2012


PS. Now a little rewrite, by the book (ANTLR Ref. p.174), so I ended 
up with:

-----------------------------------------------------------
mult_expr : (pow_expr -> pow_expr ) 
            (op=('*'|'/'|'mod'|'div') exr=pow_expr 
     -> { new BinaryExpression($op,$mult_expr.tree,$exr.tree) })*; 
-----------------------------------------------------------

but still no luck, when I run the program against the input "5*2" the 
error says:

line 1:1 missing EOF at '*'
5

The struggle continues... ;-)


More information about the antlr-interest mailing list