Question

In: Computer Science

There are two restrictions on the type of grammars that can be used with a recursive...

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.

Solutions

Expert Solution

`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.


Related Solutions

Ackermann’s function is a recursive mathematical algorithm that can be used to test how well a...
Ackermann’s function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Write a method ackermann(m, n), which solves Ackermann’s function. Use the following logic in your method: If m = 0, then return n + 1 If n = 0, then return ackermann(m-1, 1) Otherwise, return ackermann(m -1, ackermann(m, n - 1)) Test your method in a java program that displays the return values of the following method calls: ackermann(0, 0), ackermann(0,...
C++ Ackermann’s function is a recursive mathematical algorithm that can be used to test how well...
C++ Ackermann’s function is a recursive mathematical algorithm that can be used to test how well a computer performs recursion. Write a function A(m, n) that solves Ackermann’s function. Use the following logic in your function: If m = 0 then      return n + 1 If n = 0 then       return A(m−1, 1) Otherwise,          return A(m–1, A(m, n–1)) Test your function in a driver program that displays the following values: A(0, 0)   A(0, 1)   A(1, 1)    A(1,...
Classify the appropriate graph type(s) that can be used to show the association between the two...
Classify the appropriate graph type(s) that can be used to show the association between the two variables described in each situation. A health researcher wants to understand the relationship between birth weight and the mother's pre‑pregnancy body mass index (BMI) when the mother is over the age of 30 at the start of the pregnancy. He plans to use the baby's birth weight and the pre‑pregnancy BMI from the mother's medical record for this sample to analyze the BMI and...
Explain how the type of hemolysis can be used to tell apart two species that would...
Explain how the type of hemolysis can be used to tell apart two species that would look the same under the microscope. Give a specific example and describe the results for each.
Explain the importance of how Polymerase Chain Reaction, Gel Electrophoresis and Restrictions Enzymes can be used...
Explain the importance of how Polymerase Chain Reaction, Gel Electrophoresis and Restrictions Enzymes can be used in the real world.
Here are two sets of BNF grammars specifying the syntax of a language: <exp> ::= <term>...
Here are two sets of BNF grammars specifying the syntax of a language: <exp> ::= <term> | <term> + <exp> | <term> - <exp> <term> ::= <op> | <op> * <term> <op> ::= <int> | <id> | (<exp>) ********************************************* <exp> ::= <term> | <term> + <exp> | <term> - <exp> | (<exp>) <term> ::= <op> | <op> * <term> <op> ::= <int> | <id> <int> will lead to non-terminals of a digit or digit sequence '123' etc. <id> will lead...
1. How many 12-digit phone numbers can be created with the following restrictions: a) no restrictions...
1. How many 12-digit phone numbers can be created with the following restrictions: a) no restrictions b) first number cannot be zero or one. c) no repeated numbers 2. Find the number of distinguishable permutations of the letters in the following words. a) CALCULUS b) PEPPER c) MISSISSIPPI
how an induction type Instrument can be used as an AC Voltmeter
how an induction type Instrument can be used as an AC Voltmeter
How can geometry be used to promote responsible stewardship? Type Please
How can geometry be used to promote responsible stewardship? Type Please
Sample Execution : ** Recursive Euclidean Algorithm to calculate GCD ** Type a positive integer for...
Sample Execution : ** Recursive Euclidean Algorithm to calculate GCD ** Type a positive integer for A: -2 Sorry, you must enter a positive integer (>0). Please try again. ** Recursive Euclidean Algorithm to calculate GCD ** Type a positive integer for A: 35 Type a positive integer for B: 63 The GCD is 7 Write a MIPS assembly program that prompts the user for 2 positive integers (>0). Then it uses the Recursive Euclidean Algorithm to calculate GCD (the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT