Questions: Recursive Descent Parser Design

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A grammar contains the rule E → E + T | T. When you write parseExpression() for this rule in a recursive descent parser, what happens when the function is called?

AThe function correctly parses left-associative addition expressions
BThe function loops infinitely — it calls itself immediately before consuming any input
CThe function fails with a syntax error on all inputs because the rule is ambiguous
DThe function requires two tokens of lookahead to distinguish the two alternatives
Question 2 Multiple Choice

After eliminating left recursion, the rule E → E + T | T becomes E → T (('+') T)*. How does this translate into a recursive descent parser?

AA recursive call to parseExpression() at the end of the function handles the repetition
BA while loop inside parseExpression() that parses T, then keeps consuming '+' and another T
CTwo separate functions — one for E and one for the repetition — calling each other mutually
DA lookup table maps the '+' token to the correct production to avoid any looping
Question 3 True / False

Hand-written recursive descent parsers are rarely used in production compilers because automatically generated parsers (like YACC/Bison output) are more reliable and easier to maintain.

TTrue
FFalse
Question 4 True / False

In a recursive descent parser, the recursive call structure of the parsing functions directly mirrors the recursive structure of the grammar rules.

TTrue
FFalse
Question 5 Short Answer

Why does left recursion in a grammar cause infinite recursion in a recursive descent parser, and how is it eliminated?

Think about your answer, then reveal below.