[antlr-interest] Odd problem about ANTLR

John B. Brodie jbb at acm.org
Thu Jan 4 05:52:02 PST 2007


Hi!

On on Thu, 04 Jan 2007 02:20:24 -0800 (PST)), cyrix wrote:
>I try to learn ANTLR (2.7.5) to write a small
>calculator. I compose the file calc.g, generating java
>class files with ANTLR 2.7.5 (also 2.7.7 with this
>problem), it's ok. But when I compile the generated
>java files, it fails, and obviously wrong code in it. 

>...snipped...

>Can anyone tell me what's wrong ?

>...snipped...

You should put rule local variable declarations BEFORE the colon.

neg_expr returns [double result = 0]
{double value = 0;} :
    MINUS value = atom_expr {
        result = - value;
    }
    ;

and same for your other rules that declare variables.

Hope this helps...
   -jbb


More information about the antlr-interest mailing list