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

Re: Grammar for dates



Cesar Cardenas wrote:

[...]
   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

This is why you should name them both with different "names".


date = fourdigits [first]:div twodigits [second]:div twodigits

This way the first "div" will be named FirstDiv and the second SecondDiv and you will have two different method names in your generated class, you will not have "redefinition error" anymore.


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

The "naive choice" is correct in your case. ;o)


Hth,


--
best regards
Mariusz