[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Grammar for dates



Hello:

   I'am using sablecc , and I have a problem with a
grammar.

   It´s about parseing dates. The problem is that I
have a grammar that looks like:



Tokens
	div = '/';
	fourdigits = digit digit digit digit ;
	twodigits = digit digit ;

Productions	
	date =
		fourdigits div twodigits div twodigits;
  


A)   How do I deal with the " Redefinition of
AInstanteInstante.Div" java.lang.RuntimeException. I
think the mistake is in having the same token(div)
twice in the same production. As you may guess, we
should have two getDiv methods in the generated class,
but it isn't possible  in Java

     You then migt advice to move the div token to the
Helpers section, and use it from the tokens seccion.
Unfortunalely, sablecc will raise and error which
claims " PDiv and TDiv undefined."

B)   How do you tell sablecc to recognize only 4
digits (digit digit digit digit would be a naive
choice, because it doesn't scale well) . Maybe i'm
missing some sablecc feature that lets you use
"extended regular expresions" as in the following 
python (and perl) snippet:

   \d{4}/\d{2}/\d{2}



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover