[antlr-interest] Allowing random order via grammar-only notation ...
avidtrober at gmail.com
Thu Jan 29 00:15:53 PST 2009
Can grammar syntax alone accomplish this? Or, am I going to have to rely on some additional code of my own such as actions? gated predicates? other?
1. A command, COMMAND, can be followed by three modifiers, M1, M2 and M3.
2. Each modifier has its own cardinality:
3. Consecutive placement of M2 or M3 (when more than one of either is specified), can be one of two (mutually exclusive is acceptable) situations:
Case A: Modifiers can be in *any* order, e.g.
COMMAND M2 M3 M2 M3 M3 M2 M2 M1 M2
Case B: If more than one M2 or M3, they must be placed consecutively, e.g.
COMMAND M2 M2 M2 M2 M3 M3 M3 M1 M2 M2
The implicit ordering of typical grammar notation is invalidating my above requirements:
command : 'COMMAND' M1? M2* M3+ // implies M1 must come before M2 or M3, M2 before M3
Modifiers are not simple tokens, they're subrules. I realize some synpreds are needed to clear up non-determinism there. But, I want to make sure I can't do this via a grammar notation before resorting to more complexity.
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the antlr-interest