[antlr-interest] Problems with the ANTLRworks interpreter.

Peter C. Chapin pcc482719 at gmail.com
Wed Jul 30 18:26:54 PDT 2008


Hello!

I'm using ANTLRworks 1.1.7 and I'm building a grammar for a C-like 
language. I've created some unit tests for my grammar... specifically a 
collection of files containing text that is intended to be syntactically 
correct. My test program loops over these files, instantiates a parser 
for each (one at a time), and tries to parse them all. I use various 
start symbols to exercise parts of the grammar incrementally in these 
tests (helps to isolate errors).

So, given a file containing just

A = B

my test program successfully parses this using a start symbol of 
'expresion.' This is fine. However, when I use the ANTLRworks 
interpreter and enter the text 'A = B' I get a 'NoViableAltException.' I 
noticed that the interpreter is ignoring my WHITSPACE rule so I removed 
the white space from the text (using 'A=B') but that didn't help. In 
fact, the interpreter produces a NoViableAltException even when I just 
use 'A' as input text. However, a bare identifier is a valid expression 
in my target language (and it parses fine when using the test program I 
described above).

I'm think I am missing something fundamental about how the interpreter 
is supposed to work. I'm hoping someone can set my feet upon the path of 
enlightenment! I did check the on-line ANTLRworks user's guide, but the 
section on the interpreter doesn't shed much light on my question.

P.S. I do have backtracking mode turned on right now in my grammar's 
option. Could that have something to do with it?

Peter



More information about the antlr-interest mailing list