Difference between Left Factoring and Left Recursion

后端 未结 7 1178
长情又很酷
长情又很酷 2020-12-13 06:25

What is the difference between Left Factoring and Left Recursion ? I understand that Left factoring is a predictive top down parsing t

7条回答
  •  情深已故
    2020-12-13 07:11

    Left Factoring is a grammar transformation technique. It consists in "factoring out" prefixes which are common to two or more productions.

    For example, going from:

    A → α β | α γ

    to:

    A → α A'

    A' → β | γ


    Left Recursion is a property a grammar has whenever you can derive from a given variable (non terminal) a rhs that begins with the same variable, in one or more steps.

    For example:

    A → A α

    or

    A → B α

    B → A γ

    There is a grammar transformation technique called Elimination of left recursion, which provides a method to generate, given a left recursive grammar, another grammar that is equivalent and is not left recursive.


    The relationship/confusion between both terms probably derives from the fact that both transformation techniques may need to be applied to a grammar before being able to derive a predictive top down parser for it.

提交回复
热议问题