[antlr-interest] NoViableAlt

Rick Mann rmann at latencyzero.com
Tue Apr 13 15:56:04 PDT 2010


Yep! fragment is what I needed. It's been a while, I'm rusty. I originally had DIGIT below NUM, and I got other errors. Adding fragment fixed it. Thanks!

On Apr 13, 2010, at 15:37:27, Kirby Bohling wrote:

> Without actually running it, I'm pretty sure it's because '3' is
> lexing to be 'DIGIT' (it's the first rule, if DIGIT had been below NUM
> I think it might have "worked").
> 
> So the lexer returns 'DIGIT', which no rule from your parser accepts.
> You likely meant to declare the DIGIT as a fragment.  At which point,
> I think it'd start doing what you expect it to.
> 
> Kirby
> 
> On Tue, Apr 13, 2010 at 5:28 PM, Rick Mann <rmann at latencyzero.com> wrote:
>> Why do I get a "NoViableAltException" when parsing "3", but when parsing "asd" I get "asd" (in the ANTLRWorks Interpreter):
>> 
>> top     :        expr;
>> 
>> expr    :       multExpr (('+'|'-') multExpr)*;
>> multExpr:       atom ('*' atom)*;
>> atom    :       NUM | ID | '(' expr ')';
>> 
>> LETTER  :       'a'..'z' | 'A'..'Z';
>> DIGIT   :       '0'..'9';
>> ID      :       LETTER (LETTER | DIGIT)*;
>> NUM     :       DIGIT+ ('.' DIGIT+)?;
>> 
>> TIA,
>> --
>> Rick
>> 
>> 
>> List: http://www.antlr.org/mailman/listinfo/antlr-interest
>> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>> 



More information about the antlr-interest mailing list