Just add counters in the parser rules (scope probably), let there be any number 
of them, then issue errors if the counts are wrong. You really don't want to do 
things like this at the grammar level - the messages you will issue will be 
confusing to users "Error at 'y', expecting '}'" leaves you to guess the 
meaning. It is generally better to produce a CommonTree, verify it and output 
whatever you need. Every task is different though.

You can also use gated predicates or ordinary predicates perhaps, but you will 
end up with a messy grammar that isn't as easy to deal with.

Jim


> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Kaleb Pederson
> Sent: Wednesday, November 11, 2009 11:35 AM
> To: [email protected]
> Subject: [antlr-interest] Equivalent of TOKEN{x,y}
> 
> Is there an easy way to enforce in the grammar that a lexical token
> must be present a certain number of times?
> 
> For example, with TOKEN{x,y} as you might see in an extended regular
> expression, it would require that TOKEN be present at minimum x times
> and at most y times.
> 
> I know I can easily check during semantic analysis, but in this case
> I'd prefer to do so at the grammar level.
> 
> Thanks.
> 
> --
> Kaleb Pederson
> 
> Blog - http://kalebpederson.com
> Twitter - http://twitter.com/kalebpederson
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address




List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to