[antlr-interest] What multiple alternative?

James Ladd james_ladd at hotmail.com
Sat Jan 7 15:16:51 PST 2012


oops spoke too soon. Must remember to clear all errors and validate the grammar
before thinking errors are gone in ANTLRWorks.

From: james_ladd at hotmail.com
To: jbb at acm.org
CC: antlr-interest at antlr.org
Subject: RE: [antlr-interest] What multiple alternative?
Date: Sun, 8 Jan 2012 08:56:52 +1100







hmmn, I removed the error by removing the () around keyword.
I think I know what is going on. I got the idea from looking at the 
syntax diagram.

symbol
  :  IDENTIFIER
  | BINARY_SELECTOR 
  | (KEYWORD)+
  ;

Becomes:

symbol
  :  IDENTIFIER
  | BINARY_SELECTOR 
  | KEYWORD+
  ;

> Date: Sat, 7 Jan 2012 09:46:45 -0500
> From: jbb at acm.org
> To: james_ladd at hotmail.com
> CC: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] What multiple alternative?
> 
> Greetings!
> 
> On 01/07/2012 03:30 AM, James Ladd wrote:
> > array_constant
> >    : '#' array
> >    ;
> >
> > array
> >    : '(' array_element* ')'
> >    ;
> >
> > array_element
> >    : WHITESPACE
> >    | NUMBER
> >    | symbol
> >    | STRING
> >    | CHARACTER_CONSTANT
> >    | array
> >    ;
> >
> > symbol_constant
> >    : '#' symbol
> >    ;
> >
> > symbol
> >    :  IDENTIFIER
> >    | BINARY_SELECTOR
> >    | (KEYWORD)+
> >    ;
> >
> >
> 
> you have two nested repetitions but no way to know when the inner ends 
> and the outer resumes.
> e.g. zero or more array_elements each of which may contain 1 or more 
> KEYWORDS (via symbol).
> 
> consider the input: #(a:b:c:d:)
> 
> now is this a single array_element containing a single symbol having 4 
> KEYWORDs?
> or is this 4 array_elements each containing a single symbol having 1 
> KEYWORD?
> or is this 2 array_elements each containing a single symbol having 2 
> KEYWORDs?
> or is this 2 array_elements each containing 2 symbols each having 1 KEYWORD?
> or is this 3 array_elements...... you get the idea i hope
> 
 		 	   		   		 	   		  


More information about the antlr-interest mailing list