Parse Tree

  • Ambiguity: Determined by parse tree(The order of parsing)

Recursive-Descent Parsing

A left-recursive grammar can cause a recursive-descent parser, even one with backtracking, to go into an infinite loop.
So eliminate Left Recursion using left factoring

void A() {
    // Choose an A-production, A -> X1 X2 ... Xk
    for (i = 1 to k) {
        if (Xi is a nonterminal) {
            call procedure Xi();
        } else if (Xi equals the current input symbol a) {
            advance the input to the next symbol;
        } else {
            /* an error has occurred */
        }
    }
}

Alternatively (need left factoring)
image.png