[antlr-interest] Newbie: NoViableAltException

Buck, Robert rbuck at verisign.com
Tue Jul 24 16:50:38 PDT 2007


I still don't get it.

Don't the parser rules indicate what lexer rule to use? If you have the
following:

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.

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?

-Bob


> -----Original Message-----
> From: antlr-interest-bounces at antlr.org 
> [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Diehl, 
> Matthew J
> Sent: Tuesday, July 24, 2007 7:28 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Newbie: NoViableAltException
> 
> > -----Original Message-----
> > From: Buck, Robert [mailto:rbuck at verisign.com]
> > Sent: Tuesday, July 24, 2007 4:02 PM
> > To: Diehl, Matthew J; antlr-interest at antlr.org
> > Subject: RE: [antlr-interest] Newbie: NoViableAltException
> > 
> > I have no clue what you just said below. So let me start from the 
> > beginning...
> > 
> > All I want to do is define a simple recursive grammar for a 
> set-tuple 
> > syntax that has input streams like:
> > 
> > (tuple@{(attr1=value1),(attr2=value2)}={(nestedtuple1=value3),
> > (nestedtup
> > le2=value4)})
> > 
> What I was saying is that whenever there is more than one 
> PCHAR in a row, they become IDENTs (by your lexer rules).  So 
> both foo and bar are IDENTs, and not ( PCHAR )*.  So either 
> you will have to change up tuple_value or your lexer rules:
> 
> tuple_value
>   : IDENT
>   ;
> 
> > 
> > tuple
> > 	:	L_PAREN tuple_declaration EQUALS ( tuple_value | set )
> > R_PAREN
> > 	;
> > set
> > 	:	L_CURLY tuple ( COMMA tuple )*
> > 	;
> > tuple_declaration
> > 	:	tuple_key ( AT_SIGN set )? 
> > 	;
> > tuple_key
> > 	:	IDENT
> > 	;
> > tuple_value
> > 	:	( PCHAR )*
> > 	;
> > 
> > Goal: I need to be able to extract the tuple key-names and 
> the values.
> > If the value is complex (starts and ends with 
> curly-braces), I need to 
> > handle those differently by constructing references to 
> child nodes in 
> > a tree-structure of sorts. Sets are always on the right hand side.
> > 
> > So is this part correct, or not?
> > 
> > 
> > > -----Original Message-----
> > > From: antlr-interest-bounces at antlr.org 
> > > [mailto:antlr-interest-bounces at antlr.org] On Behalf Of Diehl, 
> > > Matthew J
> > > Sent: Tuesday, July 24, 2007 5:09 PM
> > > To: antlr-interest at antlr.org
> > > Subject: Re: [antlr-interest] Newbie: NoViableAltException
> > > 
> > > You're mixing your lexer and parser rules.  IDENT is 
> eating up all 
> > > of the UNRESERVED whenever there's more than one, PCHAR 
> if there's 
> > > only one.  Then you're saying that 'bar', which is more than one 
> > > UNRESERVED, so it is the token IDENT, needs to be a bunch 
> of PCHARs, 
> > > but the PCHARs have already been turned in to the token IDENT.
> > 
> > [snip...]
> > 
> 


More information about the antlr-interest mailing list