Hello everyone,
I came here because a problem came to me:
I'm actually trying to parse an EDIF file (electrical schema description). I wrote the antlr grammar from the BNF file of the EDIF standard.
Lots of rules in the BNF are define like the following example :
behaviorView ::= '(' 'behaviorView'
viewNameDef
{ comment | <nameInformation> | userData }
')'
Angled
brackets "< >" signify a construct that may occur at most once within the
immediately enclosing syntactic grouping construct. For example, { A | <B>
} represents all sequences of zero or more A's that contain at most one B; that
is, A, A A, B, A A B A, B A A A A, and the empty sequence are all valid
sequences.
I wrote in the .g4 file this rule below :
behaviorView : '(behaviorView'
viewNameDef
( comment | nameInformation | userData )*
')';However, by writing the rule in this way, I
lose the unicity of the "nameInformation'. One solution that looked logicial was to write :
behaviorView : '(behaviorView'
viewNameDef
( comment | (nameInformation)? | userData )*
')';but antlr Tool doesn't accept it ("Error : the rule "behaviorView can match an empty string").
Have you ever tried to solve this kind of problem?
Any solutions to keep the unicity?
Thanks! ;)