[antlr-interest] Please help with arbitrary arrangements and
old BNF syntax
sohail at taggedtype.net
sohail at taggedtype.net
Fri Dec 16 12:14:13 PST 2005
> Suppose I have the following parser rule snipped from edif.org:
>
> written :
> LP! "written"
> timeStamp
> ( < author > | < program > | < dataOrigin > |
> property | comment | userData )*
> RP!;
>
> Where the angle brackets mean that those can only appear once (in an
> arbitrary order). How do I enforce this in an ANTLR grammar?
Personally, I don't think this should be done in the parser. You should do
this as part of your semantic analysis (i.e. TreeParser). But thats just
IMHO.
> In a similar vein, is this the right way to limit an identifier length?
>
> IDENTIFIER
> options {testLiterals=true;} //make sure it's not a built in
> function
> : (ALPHA|'&') a:('_'|ALPHA|DIGIT)*
> {a.getText().length() < 256}? ; //less than 256 chars total
Its the easiest isn't it :)
More information about the antlr-interest
mailing list