[antlr-interest] Newbie: NoViableAltException

Diehl, Matthew J matthew.j.diehl at intel.com
Tue Jul 24 16:27:30 PDT 2007


> -----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