[antlr-interest] NoViableAlException

Joachim Schrod jschrod at acm.org
Sat Nov 13 06:55:57 PST 2010


Jim Idle wrote:

> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Joachim Schrod
>> 
>> Fabian Haupt wrote:
>> >
>> > I'm getting a NoViableAltException: line 1:55 no viable alternative
>> at
>> > input '.[CheckIntegrity'
>> >
>> > with the input of
>> > 'The lower level block specifies a right link block of 0.
>> > [CheckIntegrity+343^%SYS.DATABASE:%SYS]'
>> > starting with the 'test' rule.
>> >
>> >
>> > this is the grammar:
>> > ----------------------------
>> > grammar integrit;
>> >
>> > options {
>> >    language= Java;
>> > }
>> >
>> >
>> > test:'The lower level block specifies a right link block of '+INT+'.'
>> > WS debugnote NEWLINE;
>> >
>> > firstNodePtrWrong: INT+'. We were expecting it to point to ';
>> >
>> >
>> > debugnote:'['+ID+'+'+INT+'^%SYS.DATABASE:%SYS'+']';
>> >
>> > ID  :   ('a'..'z'|'A'..'Z')+ ;
>> > INT :   '0'..'9'+ ;
>> > NEWLINE:('\r'? '\n');
>> > WS  :   (' '|'\t')+ {skip();} ;
>> 
>> Without running it --
>> You demand a WS in the test rule that will never appear there as you
>> skip that token. Don't you mean NEWLINE there?
> 
> This is correct, you are asking for WS that will be skipped, but also, hard
> coding the specific message is so long will get you in to trouble I think.
> You are probably better off with awk for something like this I think.

If Fabian's error messages are basically just regexps, probably.
But if the information structure is context free, ANTLR is a very
good bet.

I'm currently using ANTLR to extract data from invoice texts in PDF
files and to assure that I detect all information and that the
expected invoice structure is complete and hasn't changed. This is
very hard to do with regexps, but has the same base problem as
Fabian: Lots of long constant text strings that serve basically as
keywords and mark `places' in that PDF document. ANTLR is a great
tool to accomplish structure checking, with it's parser generation
facilities. If the lexical input is highly unstructured, it's a bit
of a pain in the back, but can be handled. (I ran into similar
lexer problem as Fabian. Eventually, I resolved them by using
jflex. ;-))

Cheers,
	Joachim

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Joachim Schrod				Email: jschrod at acm.org
Roedermark, Germany



More information about the antlr-interest mailing list