Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is meant by left most derivation?

Please help me understand what is meant by Left Most Derivation the second L in LL Parser.

Explain it with a simplest example.

I saw the following picture explaining Left most derivation but I do not understand it :

enter image description here

like image 583
saplingPro Avatar asked Mar 04 '13 03:03

saplingPro


People also ask

What is the left most derivation?

Leftmost derivation − A leftmost derivation is obtained by applying production to the leftmost variable in each step. Rightmost derivation − A rightmost derivation is obtained by applying production to the rightmost variable in each step.

What is left most derivation in compiler design?

If the sentential form of an input is scanned and replaced from left to right, it is called left-most derivation. The sentential form derived by the left-most derivation is called the left-sentential form.

What is the difference between a right most derivation and a left most derivation?

In a leftmost derivation, at each step the leftmost nonterminal is re- placed. In a rightmost derivation, at each step the rightmost nonter- minal is replaced.

What are the three types of derivation?

There are three types of Derivation trees; Leftmost Derivation tree. Rightmost derivation tree. Mixed derivation tree.


1 Answers

The grammar rules are displayed on the left with Nonterminal symbols and terminal symbols. Nonterminal symbols should be Capital letters, everything else is typically a terminal symbol. In the example N and D are nonterminal and 0-9 are terminals. A Left Most Derivation ALWAYS makes the left most nonterminal go through a grammar rule. Trying to format the example below.

N
=> N D   --Replaces the first/left most/only (which is "N") with the N => N D rule
=> N D D --Replaces the first/left most nonterminal (which is "N") with the N => N D rule
=> D D D --Replaces the first nonterminal (which is "N") with the N => D rule
=> 1 D D --Replaces the first nonterminal ("D") with the D => 1 rule(our first terminal character!)
=> 1 2 D --Replaces the first nonterminal ("D") with the D => 2 rule
=> 1 2 3 --Replaces the first nonterminal ("D") with the D => 3 rule
-- Only terminal characters remain, derivation/reduction is complete.
like image 75
Infinite Possibilities Avatar answered Sep 22 '22 04:09

Infinite Possibilities