[antlr-interest] Please help with arbitrary arrangements and old BNF syntax

sohail at taggedtype.net sohail at taggedtype.net
Fri Dec 16 12:16:49 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.

Although, now that I think of it, perhaps you could use booleans and gate
the < author > rule with a semantic predicate like {!seenAuthor}? < author
> {seenAuthor=true;}

Something like this atleast. But then your use won't know exactly why it
failed (I think)


More information about the antlr-interest mailing list