[antlr-interest] ANTLR 3 matching an exact number or bounded number of items

Kevin J. Cummings cummings at kjchome.homeip.net
Wed Mar 2 18:20:10 PST 2011


On 03/02/2011 09:09 PM, The Researcher wrote:
> Does ANTLR 3 have built-in support for matching an exact number or bounded
> number of items that does not rely on using {...}?=>
> 
> e.g for a 32 bit value of four bytes the rule statement would be
>     byte[4]
> 
> or for an a structure that has a bound of elements between 1 and 16 the rule
> statement would be
>     struc[1:16]
> While ANTLR 3 uses [ ] for rule parameters, here [ ] is used to signify
> element bounds.
> 
> I have looked high and low for this, and found nothing tangible.
> 
> Abusing {...}?=> works, but I would like to stop abusing it.

Set up the action code for your rule to count the number of elements
matched.  When you exceed the number you need, have the action output an
error, or raise an exception, or, ....

Or you can abuse gated semantic predicates.

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

-- 
Kevin J. Cummings
kjchome at verizon.net
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list