- What is the difference between factor and term? using the same example
I am not giving the same example as I will not give you a clear idea of ββwhat you doubt!
Considering,
term ::= term * factor | factor factor ::= number | (expression)
Now suppose, if I ask you to find the factors and terms in the expression 2 * 3 * 4. Now that the multiplication remains associative, it will be evaluated as: -
(2*3)*4
As you can see, here (2 * 3) is the term and the coefficient is 4 (number). Likewise, you can extend this approach to any level to draw on an idea of ββterms.
In accordance with this grammar, if in this expression there is a chain of multiplication, then its part, leaving one factor, is a term that, in turn, gives another part - another term, leaving another one factor and so on. Here's how expressions are evaluated.
- Why can't a recursive descent parser process outputs with left recursion? (Explain the second quote).
Your second statement is completely clear in essence. A recursive descent parser is a kind of top-down parser built from a set of mutually recursive procedures (or a non-recursive equivalent), where each such procedure usually implements one of the grammar derivatives.
This is said so because it is clear that the recursive descent parser will enter an infinite loop if the nonterminal continues to expand in itself.
Similarly, speaking of a recursive descent parser, even with backtracking --- When we try to expand a nonterminal, we may eventually try to expand the same nonterminal again without consuming any input.
A-> Ab
Here, when expanding the non-terminal A, you can continue to expand in
A-> AAb -> AAAb -> ... -> infinite loop of A.
Therefore, we prevent left-recursive statements when working with recursive descent parsers.