Intermediate Compilers & Programming Language Theory
Q61 / 100

Why can left recursion break a recursive descent parser?

Correct! Well done.

Incorrect.

The correct answer is A) Because the parsing function for the non-terminal would call itself again before consuming any input, causing infinite recursion and stack overflow

A

Correct Answer

Because the parsing function for the non-terminal would call itself again before consuming any input, causing infinite recursion and stack overflow

Explanation

A rule like expr -> expr + term makes parseExpr() immediately call parseExpr() again with no token consumed, looping forever. The standard fix is to rewrite the grammar to be right-recursive or to use an iterative loop with left-factoring.

Progress
61/100