In: Computer Science
There are two restrictions on the type of grammars that can be used with a recursive descent parser. The first is that the grammar cannot have any left recursive productions. Give an example of a left recursive production and explain why such productions would be a problem.
The second restriction is that the grammar must not require more than one token look ahead. Give an example of a production that does not have this property. Explain why this restriction is necessary for recursive descent parsing.
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
Recursive nonterminals in grammars are not unusual and useful, and allow grammars to explain an endless range of inputs. However, left recursion is a particular form of recursion that can't be at once dealt with by using the simple LL(1) parsing algorithm. Left recursion just refers to any recursive nonterminal that, while it produces a sentential form containing itself, that new reproduction of itself seems on the left of the production rule. Because left recursion is a useful tool for grammar writers, everybody writing an LL(1) parser generator have to take the time to find a workaround for this weakness of the LL(1) algorithm. Fortuitously, workarounds exist.
We expect the primary production (seq -> item) to be diagnosed when the central object is seen, and the second to be diagnosed for any additional item that complies with inside the collection. (at some point of these examples, I'm ignoring the difficulty of what exactly terminates a listing of the object -- it's far possibly defined via surrounding grammar not present in this fragment.)
The LL(1) parsing set of rules wishes to realize, for each non-terminal, what production to pick out based on looking at the subsequent enter token. In this example, when the parser decides it ought to assume a seq, it cannot choose which of those productions should observe, because each production can start (immediately or not directly) with an object. The situation is called "left recursion" due to the fact seq can time and again amplify into itself at the left:
Kindly revert for any queries
Thanks.