[antlr-interest] Interpreter exceptions?

Natan nvivo.misc at gmail.com
Thu Jul 9 13:50:12 PDT 2009


Hi,

I'm still learning AntLr, but something is bothering me, maybe someone 
here can explain this.

Given a very simple test grammar like:

prog
    :    STRING;

STRING
    :    '"' ( '\"' | ~('"') )* '"';


I debug using "test" as input, and it works fine and shows me a tree 
like: root -> prog -> "test"

But from the interpreter, it shows me: <grammar X> -> prog -> 
MismatchedTokenException(-1!=4)
and the console says:

[17:27:48] Interpreting...
[17:27:48] problem matching token at 1:2 MismatchedTokenException(116!=34)
[17:27:48] problem matching token at 1:3 MismatchedTokenException(101!=34)
[17:27:48] problem matching token at 1:4 MismatchedTokenException(115!=34)
[17:27:48] problem matching token at 1:5 MismatchedTokenException(116!=34)
[17:27:48] problem matching token at 1:6 NoViableAltException('?'@[()* 
loopback of 11:8: ( '\"' | ~ ( '"' ) )*])

I am aware that the debug and interpreter trees are not the same, and 
that the interpreter does not support some things like actions etc, but 
still this simple syntax should work right?

Actually, I was trying to create a more complex grammar, until I started 
to see these exceptions. Made me crazy for days until I realized the 
actual compiled code was working fine.

So, is this because the interpreter is not the same as the code 
generated by antlr?
Or do I need to add something to my grammar to be able to test inputs 
using the interpreter?
Or the interpreter is in beta stage and I should not believe anything it 
says for now?

Thanks!


More information about the antlr-interest mailing list