[antlr-interest] How can I make sure there's one such rule in the input ?

Jim Idle jimi at temporal-wave.com
Wed Feb 16 21:10:33 PST 2011


You don't. You add a counter and parse everything that comes up, then you
issue a semantic error saying that there are too many inputStatements.
Always push the errors as far down the chain as you can as they gain more
context and are therefore clearer to the end user.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of devdoer bird
> Sent: Wednesday, February 16, 2011 9:05 PM
> To: antlr-interest Interest
> Subject: [antlr-interest] How can I make sure there's one such rule in
> the input ?
>
> HI:
>
> I have the grammar:
>
> statements:(inputStatement|schemaStatement|filtersStatement|COMMENT)*
> EOF;
>
>
> As you see ,it will match as many inputStatements as there are in the
> input file.
>
>
> How can change the grammar to  make sure there is only one
> inputStatment in the input file?
>
>
> Thanks.
>
> 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