[antlr-interest] NoViableAlException

Joachim Schrod jschrod at acm.org
Thu Nov 11 19:00:42 PST 2010


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?

Btw, are you aware that '+' does not mean concatenation in ANTLR,
as it does in Java? It means `repeat one or more times' for the
previous token. Probably most of your pluses should be changed to
spaces. And use parenthesis in your INT definition, for enhanced
readability. You may leave them off at NEWLINE instead...

Then you'll propably run into problems since any '.' that's
followed by ' ' start the recognition of '. We were expecting it to
point to ', without the ability to backtrack when some other
character happens to be the 3rd char -- and that's probably neither
what you want.

Pull your strings out of the parser rules, make proper tokens for
them, and provide token definitions that match all prefixes of your
constant strings. Without that you're going to have a long fight
against the windmill before you.

I hope that gives you some ideas for your further problem analysis,

	Joachim

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



More information about the antlr-interest mailing list