[antlr-interest] Newbie: NoViableAltException

Randall R Schulz rschulz at sonic.net
Tue Jul 24 17:10:01 PDT 2007


On Tuesday 24 July 2007 16:50, Buck, Robert wrote:
> I still don't get it.
>
> Don't the parser rules indicate what lexer rule to use? If you have
> the following:

Nope. Again, the lexical analyzer operates independently and essentially 
asynchronously w.r.t. the parser. The parser _DOES NOT_ direct the 
actions of the scanner.


> IDENT EQUALS (PCHAR)*
>
> The IDENT lexer rule would not get called for any tokens to the RHS
> of the EQUALS sign, right? I declared it only gets called for the
> LHS.

Scanner rules are NOT "called" by the parser. They are used to partition 
the input stream and assign token type codes to each sub-sequence of 
the input. Then, when that's all done and the entire input is broken 
into tokens, the parser starts in on those tokens.


> The same with my grammar, IDENT is always to the left hand side of an
> EQUALS and (PCHAR)* can only occur on the right hand side.
>
> This was the way lex/yacc worked as far as I recall. Doesn't ANTLR
> work that way too?

As Terence has recently stated, forget everything you know about lex and 
yacc. Little of the details of that system will serve you well with 
ANTLR.


> -Bob


Randall Schulz


More information about the antlr-interest mailing list