RCIX
RCIX

Reputation: 39437

Odd behavior of parser when trying sample grammar

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:

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

Upvotes: 0

Views: 99

Answers (2)

peter.murray.rust
peter.murray.rust

Reputation: 38043

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.

Upvotes: 1

Amber
Amber

Reputation: 526613

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;}
        )*

Upvotes: 1

Related Questions