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

Jim Idle jimi at temporal-wave.com
Wed Mar 2 18:52:24 PST 2011


That's because what you ask for is not the right way to do it. As per
prior posts ad nausea (as Private Eye would say), you should be as loose
as you can be with the syntax rules and make lots of semantic checks in a
later pass. If you do what you are asking for you will end up with an
error message such as:

Syntax error at 2B, not expecting 2B, expecting ';'

Whereas with a semantic check, you will parse as many as you see and
produce a tree (or you could issue this in the parser but best not to
really), that with a verification walk says:

... 33 44 55 66 2B 43 33 ;
                ^^^^^^^^

Too many bytes specified, there can be only 4 and you have 7.

You will also maximize the number of real errors that you can capture in
one pass.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of The Researcher
> Sent: Wednesday, March 02, 2011 6:09 PM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] ANTLR 3 matching an exact number or bounded
> number of items
>
> 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.
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> email-address


More information about the antlr-interest mailing list