[antlr-interest] NoViableAlException

Fabian Haupt fabian at fabianhaupt.de
Fri Nov 12 15:40:59 PST 2010


I've figured the + things out, sry about that. It's been a long time 
since I wrote my last antlr grammar.

I'll do the refactorings you suggested and let you know how it turns out
:)

Thanks for your time!

cheers,
Fabian

On 11/12/2010 04:00 AM, Joachim Schrod wrote:
> 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
>


More information about the antlr-interest mailing list