Clifford Heath
2/10/2008 6:19:00 AM
Day wrote:
> The ordering of things DOES matter, right? Or am I hallucinating?
The ordering of rules in a grammar doesn't matter at all.
The compiler processes each rule into a method (and some
modules that extend objects created in that method), and
it does that without considering the existence of any other
rule. Just as order of def's in a class doesn't matter, the
order of rules in a grammar doesn't matter.
On the other hand, the order of alternatives within a rule
does matter. Once one alternative succeeds, even if it leaves
the input at a point where the calling rule cannot succeed,
no other alternative will ever be tried. You may need to use
lookahead to prevent this happening.
Finally, the success of one item in a sequence is final. If
the path chosen prevents following items in that sequence to
fail, the previous item will never be revisited, and the whole
sequence will fail. Again, you might need to use lookahead
to prevent this - especially to place limits on repetition.
This is looking like becoming an FAQ, and I hope I'm getting
better at stating it succinctly. I also hope Google starts
finding it, so I don't have to :-).
Clifford Heath.