1

Left Factoring (LF), Left Recursion (LR) and Non-deterministic in Grammar | Comp...

 1 year ago
source link: https://www.geeksforgeeks.org/videos/left-factoring-left-recursion-and-non-determinism-in-grammar-compiler-design/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Left Factoring (LF), Left Recursion (LR) and Non-deterministic in Grammar

Left Factoring (LF), Left Recursion (LR) and Non-deterministic in Grammar | Compiler Design
Hello everyone. I hope you all are doing
  • 80 Views
  • 11/07/2022

<p>In this video, we will be covering what is Non-deterministic grammar, left factoring & left recursion in detail.

Let us first see what is non-deterministic grammar.

Grammar having common prefixes is called non-deterministic grammar. Such grammar requires backtracking due to confusion, which is actually a costly process. After tracing the first input “A”, there are two available options. So, the confusion is to go with b1, b2, or b3. Due to this confusion, Top-Down Parsers don’t prefer to parse Non-Deterministic Grammar.

The process of removing this confusion is called eliminating non-determinism or Left Factoring. Most of the parsers avoid parsing grammar with non-deterministic behaviour, so we must remove non-determinism from the grammar before passing the grammar to parser.

It is a procedure of factoring out common prefixes as long as possible. It is generally used in case when it’s not clear which of two available options should be used to expand LHS non-terminal. This grammar that is obtained after left-factoring is known as Left Factored Grammar. With left factored grammar compiler no longer needs backtracking. As backtracking is a costly procedure, so it can be avoided using left factored grammar. Left factoring can be applied to the grammar multiple times until the grammar becomes deterministic and unambiguous.

Any Grammar G (V, T, P, S) can be said as left-recursive grammar if it is having production of the form: A → A α | β, where V means variable, T means Terminal, P means production rules, and S means Starting Symbol. It is called left-recursive because the LHS of the production is again occurring at first place on the RHS of the production. Such left recursion is said to be a problematic condition for the Top-down parsers.

So, it is very necessary to eliminate left recursion from grammar.

Introduction of parsing ambiguity & parsers: https://www.geeksforgeeks.org/introduction-of-parsing-ambiguity-and-parsers-set-1/ Removing direct & indirect left recursion in grammar: https://www.geeksforgeeks.org/removing-direct-and-indirect-left-recursion-in-a-grammar/</p>


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK