views:

35

answers:

2

I'm trying to get the feel for antlr3, and i pasted the Expression evaluator into an ANTLRWorks window (latest version) and compiled it. It compiled successfully and started, but two problems:

  • Attempting to use a input of 1+2*4/3; resulted in the actual input for the parser being 1+2*43.
  • One of the errors it shows in it's graphical parser tree is MissingTokenException(0!=0).

As i'm new to antlr, can someone help?

+1  A: 

The example you linked to doesn't support division (just look at the code, you'll notice there's no division here:

expr returns [int value]
    :   e=multExpr {$value = $e.value;}
        (   '+' e=multExpr {$value += $e.value;}
        |   '-' e=multExpr {$value -= $e.value;}
        )*
Amber
Oh. Artifact of previous example i was trying i guess. Hang on let me try a better example!
RCIX
Yup it works now, how did i miss that?
RCIX
+1  A: 

We often get

MissingTokenException(0!=0)

when we make mistakes. I think it means that it cannot find a token it's looking for, and could be produced by an incorrect token. It's possible for the parser to "recover" sometimes depending on the grammar.

Remember also that the LEXER operates before the parser and your should check what tokens are actually passed to the parser. The AntlrWorks debugger can be very helpful here.

peter.murray.rust
i've just never seen a program state that before :)
RCIX