Difference between Left Factoring and Left Recursion

后端 未结 7 1156
长情又很酷
长情又很酷 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:18

    Here is a simple way to differentiate between both terms:

    • Left Recursion: When leftmost Element of a production is the Producing element itself (Non Terminal Element).

    e.g. A -> Aα / Aβ

    • Left Factoring: When leftmost Element of a production (Terminal element) is repeated in the same production.

    e.g. A -> αB / αC

    Furthermore, If a Grammar is Left Recursive, it might result into infinite loop hence we need to Eliminate Left Recursion.

    If a Grammar is Left Factoring, it confuses the parser hence we need to Remove Left Factoring as well.

    0 讨论(0)
提交回复
热议问题