Why is the Alternative symbol of the ECMAScript RegExp grammar left recursive?
I cannot for the life of me figure out why Alternative is left recursive. It really throws a wrench into my parser.
Alternative :: [empty] Alternative Term
Here is a note in the semantics portion of the spec that is not exactly clear. Maybe the reasoning would be revealed once I understand this?
NOTE Consecutive Terms try to simultaneously match consecutive portions of the input String. If the left Alternative, the right Term, and the sequel of the regular expression all have choice points, all choices in the sequel are tried before moving on t开发者_C百科o the next choice in the right Term, and all choices in the right Term are tried before moving on to the next choice in the left Alternative.
What kind of parser can properly handle a left recursive grammar?
Because for certain types of parser left-recursion is much better (e.g. for yacc - see section 6.2 here for an explanation).
If it's causing trouble for your particular parser, then by all means swap it over - it doesn't affect the definition of the language in any way.
精彩评论