[antlr-interest] Problem with existence of the same literal in two rules

Anakreon Mejdi amejdi at ertonline.gr
Wed Apr 30 07:49:06 PDT 2003


STRING:
	('L'|'H'|'Z'|'X') {/*set the token type into an imaginary
token*/}
|('a'..'z' | 'A'..'Z')+ (INT)
;

If antlr complains for ambiguity put a predicate .
	
ramyasivadas wrote:
> Hi,
> 
> Let me quote an example to help me explain the problem.
> 
> I have a rule as follows
> STRING
> :('a'..'z' | 'A'..'Z')+ (INT)
> ;
> 
> I also have a rule
> WFCS
> :'L'|'H'|'Z'|'X'
> ;
> 
> INT
> :('0'..'9')+
> ;
> 
> The issue is, if I have a set of literals constituting a rule and if 
> one or more of the same literals form a part of another independent 
> rule, the parser generates an exception. How can I avoid this.
> 
> For example, the rule STRING is defined to be made up of a 
> combination of any alphabets followed by a numeral. Another rule WFCS 
> which has nothing to do with STRING can be made up of a combination 
> of L,H,Z and/or X.
> 
> When the parsing for WFCS block is done, the parser expects an INT 
> after the alphabet. I assume it is applying the STRING rule on the 
> WFCS block since it has encountered an alphabet. Can we override this 
> behaviour.
> 
> 
> Thanks in advance.
> 
> Regards,
> Ramya
> 
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list