dcsimg
Specifying limit on number of digits in the Grammar in ANTLR
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   bharath_R
Posted On:   Monday, April 23, 2007 10:08 AM

I want to limit the number of digits in a number upto 5. Below is the ABNF format


ID: 1*5(DIGIT)

DIGIT: '0'..'9'


i.e the ID can be any number varying from a 1 digit number to a max of 5digit number. Each digit varying between 0 and 9.


How do I achieve this is ANTLR? I have been trying to write an equivalent EBNF format but without success.


Thanks for you help.

Re[2]: Specifying limit on number of digits in the Grammar in ANTLR

Posted By:   Julien_FURET  
Posted On:   Wednesday, April 25, 2007 05:50 AM

Damn it ! I should look better before answering !!! I did not see the previous message :-p

So I guess my idea wasn't so bad after all

Re: Specifying limit on number of digits in the Grammar in ANTLR

Posted By:   Julien_FURET  
Posted On:   Wednesday, April 25, 2007 05:48 AM

Warning : this is a really dirty way to resolve your problem, but why not trying :

ID: DIGIT (DIGIT)? (DIGIT)? (DIGIT)? (DIGIT)?
DIGIT: '0'..'9'

If you find a cleaner solution, please let me know because I could use it in the future !

Hope it helps.

Re: Specifying limit on number of digits in the Grammar in ANTLR

Posted By:   Anonymous  
Posted On:   Tuesday, April 24, 2007 07:27 PM

ID: DIGIT DIGIT? DIGIT? DIGIT? DIGIT?


DIGIT: '0'..'9'





That's my ugly little guess. =)
Not very scalable (Good thing you don't want 142 digits). You might want to wait for someone that knows WTF they are talking about though.

-J.T.
About | Sitemap | Contact