[antlr-interest] Order independent keywords
Jim Idle
jimi at temporal-wave.com
Sun Mar 22 08:10:38 PDT 2009
register reg.ini wrote:
> Hi everybody,
> I am trying to parse a custom configuration file format using antlr.
> This file format describes properties of several Paramaters using C
> like structs, for example:
>
> Record
> {
> TYPE typeid;
> LENGHT 80;
> PATH= pathtofile
> }
>
> . The order of the attributes is irrelevant but some of them are
> required other are simply optional. Is it possible to embody the
> requirement of order independent attributes directly in the parser
> grammar, without using actions?
Probably not, but that is exactly the wrong way to do it anyway. You
want to specify that you can have any number of options, including 0,
and accumulate how many you get of each , with their line numbers and so
on. Then you can tell the users: "Too many pggb options (There can be
only one) at line 44', or "Record specs must contain a gurgle option and
this is missing from the Record at line ...."
So you will need actions either in the parser or (better) in the tree
walker. Remember to push as many errors as possible as high up the chain
as they can go - overall, you have better semantic context for the
message and your users will thank you for the better error messages.
Jim
More information about the antlr-interest
mailing list