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

mzukowski at yci.com mzukowski at yci.com
Wed Apr 30 08:16:19 PDT 2003


An alternative approach would be to not have WFCS in your lexer.  Instead
use a parser rule like this:

wfcs: {isWcfs(LA(1))}? s:STRING {s.setType(WCFS);}

Then write the isWcfs method to check that is is only one char long and is a
correct character.

Monty

-----Original Message-----
From: Anakreon Mejdi [mailto:amejdi at ertonline.gr]
Sent: Wednesday, April 30, 2003 7:49 AM
To: antlr-interest at yahoogroups.com
Subject: Re: [antlr-interest] Problem with existence of the same literal
in two rules


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/ 


 

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




More information about the antlr-interest mailing list