Reputation: 175
I understand that an LL parser (no lookahead) cannot deal with left recursive rules due to the fact it will keep on predicting the left recursive non terminal over and over again and would never be able to match.
But what if we adopted the combination of 2 strategies:
So, suppose we have a left recursive rule as follows:
A -> As | a
Where s is a string composed of terminals and non terminals.
If either s generates strings with minimum length greater than 0, then even though when faced with the non terminal "A" in a prediction we would be predicting "A s" over and over again, the minimum length of the predicted string would only grow, eventually surpassing the length of the input string and therefore being discarded.
Of course this wouldn't work with grammars that are infinitely ambiguous (like the ones that have loops), leading us to the second strategy:
This effectively discards infinitely many derivations, though it preserves the language accepted by the parser.
As a concrete example, suppose the following grammar:
S -> Sa | a
The minimum length of the strings generated by the non terminal S is 1.
Now suppose we're parsing the following input string: aa.
Would this work? Am I missing something?
Upvotes: 2
Views: 450