SlideShare a Scribd company logo
1 of 21
Derivations
and Languages
-Sampath Kumar S,
AP/CSE, SECE
Derivations and Languages
 While inferring whether the given input strings
belongs to the given CFG, we can have 2
approaches:
 Using the rules from body to head (Recursive
Inference)
 Using the rules from head to body (Derivation)
11/21/2017
Sampath Kumar S, AP/CSE, SECE
2
Derivation using Grammar
Recursive Inference Derivation
Left Most
Derivation
Right Most
Derivation
Recursive Inference:
 Here we take string from each variables,
concatenate them in proper order and infer that the
resulting string is in the language of the variable in
the head
11/21/20173
Sampath Kumar S, AP/CSE, SECE
Derivation:
 Here we use the production from head to body i.e.,
from start symbol expanding till reaches the given
string. This use of grammar is called derivation.
11/21/20174
Sampath Kumar S, AP/CSE, SECE
Problems to discuss:
61. For the language L = {wcwR | w (0+1)*} check
whether the string 01c10 belongs to the language
L or not.
Solution:
Step 1: For the language L, the productions are
S → 0S0 | 1S1 | C
Step 2: Derivation
S → 0S0 [∵ S → 0S0]
→ 01E10 [∵ S → 1S1]
→ 01c10 [∵ S → c]
11/21/2017
Sampath Kumar S, AP/CSE, SECE
5
Understanding the Language
defined by CFG:
 The only way to recognize the language, is to try
out various strings from the given production rules.
 Then by observing the derived strings, one can
find out the language generated from the given
CFG.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
6
Problems to discuss:
62. Derive ‘a4’ from the grammar G=({S}, {a},P,S)
where P: S → aS|ε.
63. Find L(G) and derive the string ‘abbab’ for the
grammar G=({S}, {a},P,S) where
P: S → aS|bS|a|b.
64. Find L(G) and derive the string ‘abbaaba’ for the
grammar G=({S,X}, {a},P,S) where
P: S → XaaX, X → aX|bX|ε.
65. Find L(G) for the grammar G=({S,C}, {a,b},P,S)
where P is given by S → aCa, C → aCa|b.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
7
Leftmost and Rightmost Derivation:
 If a word w is generated by a CFG by a certain
derivation and at each step in the derivation, a rule
of production is applied to the leftmost non
terminal in the working string, then this derivation
is called leftmost derivation (LMD).
 If a word w is generated by a CFG by a certain
derivation and at each step in the derivation, a rule
of production is applied to the rightmost non
terminal in the working string, then this derivation
is called rightmost derivation (RMD).
11/21/2017
Sampath Kumar S, AP/CSE, SECE
9
Problems to discuss:
66. Consider the CFG ({S,X}, {a,b}, P, S} where
productions are S → baXaS|ab, X →Xab|aa. Find
the LMD and RMD for the string
w=baaaababaab.
67. Consider the CFG S → aB|bA
A → a | aS | bAA
B → b | bS | aBB
Find the LMD and RMD for the string
W=aabbabba.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
10
Derivation Tree:
 A derivation tree or parse tree is an ordered
rooted tree that graphically represents the
semantic information a string derived from a
Context - Free Grammar.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
11
Representation Technique
 Root vertex − Must be labeled by the start
symbol.
 Vertex − Labeled by a non-terminal symbol.
 Leaves − Labeled by a terminal symbol or ε.
If S → x1x2 …… xn is a production rule in a
CFG, then the parse tree / derivation tree will be
as follows −
11/21/2017
Sampath Kumar S, AP/CSE, SECE
12
Approaches for constructing
Derivation Tree:
There are two different approaches to draw a
derivation tree −
 Top-down Approach −
 Starts with the starting symbol S
 Goes down to tree leaves using productions
 Bottom-up Approach −
 Starts from tree leaves
 Proceeds upward to the root which is the starting
symbol S
11/21/2017
Sampath Kumar S, AP/CSE, SECE
13
Derivation or Yield of a Tree:
 The derivation or the yield of a parse tree is the
final string obtained by concatenating the labels of
the leaves of the tree from left to right, ignoring the
Nulls.
 However, if all the leaves are Null, derivation is
Null.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
14
Sentential Form and Partial
Derivation Tree:
 A partial derivation tree is a sub-tree of a
derivation tree/parse tree such that either all of its
children are in the sub-tree or none of them are in
the sub-tree.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
15
Leftmost and Rightmost
Derivation of a String
 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.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
16
Left and Right Recursive Grammars
 In a context-free grammar G, if there is a
production in the form X → Xa, where X is a non-
terminal and ‘a’ is a string of terminals, it is called
a left recursive production. The grammar having
a left recursive production is called a left
recursive grammar.
 If in a context-free grammar G, if there is a
production is in the form X → aX where X is a non-
terminal and ‘a’ is a string of terminals, it is called
a right recursive production. The grammar
having a right recursive production is called a right
recursive grammar.
11/21/2017
Sampath Kumar S, AP/CSE, SECE
17
Problems to discuss:
68. Let a CFG G= { {S}, {a, b}, P, S} Where
P = S → SS | aSb | ε. Draw derivation tree for the
string “abaabb”
 One derivation form of the above CFG is
S → SS → aSbS → abS → abaSb → abaaSbb → abaabb
11/21/2017
Sampath Kumar S, AP/CSE, SECE
18
Problems to discuss:
69. Let any set of production rules in a CFG be X →
X+X | X*X |X| a over an alphabet {a}. Find LMD and
RMD for string "a+a*a“.
70. Construct Parse tree for the string a*(a+b00) for the
following CFG using left and right most derivation.
E → A | E + E | E * E | (E)
A → a | b |Aa | Ab | A0 | A1
71. Construct Parse tree for the string a*(a+a) for the
following CFG using left and right most derivation.
E → E + E | E * E | (E) | a
11/21/2017
Sampath Kumar S, AP/CSE, SECE
19
Problems to discuss:
72. Generate parse tree for the string 00101 using
left and right most derivation for following CFG
S → A1B, A → 0A|ε | B → 0B | 1B | ε
73. Generate parse tree for the string babbab using
left and right most derivation for following CFG
S → aSa | bSb | a |b | ε
11/21/2017
Sampath Kumar S, AP/CSE, SECE
20
11/21/2017
Sampath Kumar S, AP/CSE, SECE
21
நன்றி
11/21/2017
Sampath Kumar S, AP/CSE, SECE
22

More Related Content

What's hot

Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksMohammad Vaseem Akaram
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure callSunita Sahu
 
Predicate Logic
Predicate LogicPredicate Logic
Predicate Logicgiki67
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generationVipul Naik
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular setsSampath Kumar S
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryTsegazeab Asgedom
 
Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Abhimanyu Mishra
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed systemSunita Sahu
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prologbaran19901990
 
Static and dynamic scoping
Static and dynamic scopingStatic and dynamic scoping
Static and dynamic scopingNusratShaikh16
 
Advanced topics in artificial neural networks
Advanced topics in artificial neural networksAdvanced topics in artificial neural networks
Advanced topics in artificial neural networksswapnac12
 
A simple approach of lexical analyzers
A simple approach of lexical analyzersA simple approach of lexical analyzers
A simple approach of lexical analyzersArchana Gopinath
 
System models in distributed system
System models in distributed systemSystem models in distributed system
System models in distributed systemishapadhy
 

What's hot (20)

A* Search Algorithm
A* Search AlgorithmA* Search Algorithm
A* Search Algorithm
 
Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocks
 
RPC: Remote procedure call
RPC: Remote procedure callRPC: Remote procedure call
RPC: Remote procedure call
 
Predicate Logic
Predicate LogicPredicate Logic
Predicate Logic
 
Report on c
Report on cReport on c
Report on c
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets1.10. pumping lemma for regular sets
1.10. pumping lemma for regular sets
 
Chapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata TheoryChapter1 Formal Language and Automata Theory
Chapter1 Formal Language and Automata Theory
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2Theory of Automata and formal languages unit 2
Theory of Automata and formal languages unit 2
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
 
3 algorithm-and-flowchart
3 algorithm-and-flowchart3 algorithm-and-flowchart
3 algorithm-and-flowchart
 
10 logic+programming+with+prolog
10 logic+programming+with+prolog10 logic+programming+with+prolog
10 logic+programming+with+prolog
 
Static and dynamic scoping
Static and dynamic scopingStatic and dynamic scoping
Static and dynamic scoping
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
Advanced topics in artificial neural networks
Advanced topics in artificial neural networksAdvanced topics in artificial neural networks
Advanced topics in artificial neural networks
 
Assembly 8086
Assembly 8086Assembly 8086
Assembly 8086
 
A simple approach of lexical analyzers
A simple approach of lexical analyzersA simple approach of lexical analyzers
A simple approach of lexical analyzers
 
System models in distributed system
System models in distributed systemSystem models in distributed system
System models in distributed system
 

Similar to CFG Derivations Languages Parse Trees

4. languages and grammars
4. languages and grammars4. languages and grammars
4. languages and grammarsSaeed Parsa
 
2.3 context free grammars and languages
2.3 context free grammars and languages2.3 context free grammars and languages
2.3 context free grammars and languagesSampath Kumar S
 
Lefmost rightmost TOC.pptx
Lefmost rightmost TOC.pptxLefmost rightmost TOC.pptx
Lefmost rightmost TOC.pptxJisock
 
2.8 normal forms gnf & problems
2.8 normal forms   gnf & problems2.8 normal forms   gnf & problems
2.8 normal forms gnf & problemsSampath Kumar S
 
2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammarsSampath Kumar S
 
Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3Abhimanyu Mishra
 
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptxShubhamKumar483645
 
lec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdflec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdfwigewej294
 
Chapter3pptx__2021_12_23_22_52_54.pptx
Chapter3pptx__2021_12_23_22_52_54.pptxChapter3pptx__2021_12_23_22_52_54.pptx
Chapter3pptx__2021_12_23_22_52_54.pptxDrIsikoIsaac
 

Similar to CFG Derivations Languages Parse Trees (11)

4. languages and grammars
4. languages and grammars4. languages and grammars
4. languages and grammars
 
2.3 context free grammars and languages
2.3 context free grammars and languages2.3 context free grammars and languages
2.3 context free grammars and languages
 
Lefmost rightmost TOC.pptx
Lefmost rightmost TOC.pptxLefmost rightmost TOC.pptx
Lefmost rightmost TOC.pptx
 
2.8 normal forms gnf & problems
2.8 normal forms   gnf & problems2.8 normal forms   gnf & problems
2.8 normal forms gnf & problems
 
2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars2.5 ambiguity in context free grammars
2.5 ambiguity in context free grammars
 
Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3Theory of Automata and formal languages Unit 3
Theory of Automata and formal languages Unit 3
 
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
5045.-Compiler-Design-Left-Recursion-and-Left-Factoring.pptx
 
Context free grammar
Context free grammarContext free grammar
Context free grammar
 
Unit iii
Unit iiiUnit iii
Unit iii
 
lec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdflec02-Syntax Analysis and LL(1).pdf
lec02-Syntax Analysis and LL(1).pdf
 
Chapter3pptx__2021_12_23_22_52_54.pptx
Chapter3pptx__2021_12_23_22_52_54.pptxChapter3pptx__2021_12_23_22_52_54.pptx
Chapter3pptx__2021_12_23_22_52_54.pptx
 

More from Sampath Kumar S

5.2 primitive recursive functions
5.2 primitive recursive functions5.2 primitive recursive functions
5.2 primitive recursive functionsSampath Kumar S
 
4.7. chomskian hierarchy of languages
4.7. chomskian hierarchy of languages4.7. chomskian hierarchy of languages
4.7. chomskian hierarchy of languagesSampath Kumar S
 
4.3 techniques for turing machines construction
4.3 techniques for turing machines construction4.3 techniques for turing machines construction
4.3 techniques for turing machines constructionSampath Kumar S
 
4.2 variantsof turing machines (types of tm)
4.2 variantsof turing machines (types of tm)4.2 variantsof turing machines (types of tm)
4.2 variantsof turing machines (types of tm)Sampath Kumar S
 
3.6 & 7. pumping lemma for cfl & problems based on pl
3.6 & 7. pumping lemma for cfl & problems based on pl3.6 & 7. pumping lemma for cfl & problems based on pl
3.6 & 7. pumping lemma for cfl & problems based on plSampath Kumar S
 
3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cflSampath Kumar S
 
3.1,2,3 pushdown automata definition, moves & id
3.1,2,3 pushdown automata   definition, moves & id3.1,2,3 pushdown automata   definition, moves & id
3.1,2,3 pushdown automata definition, moves & idSampath Kumar S
 
2.7 normal forms cnf & problems
2.7 normal forms  cnf & problems2.7 normal forms  cnf & problems
2.7 normal forms cnf & problemsSampath Kumar S
 
2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammar2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammarSampath Kumar S
 
1.9. minimization of dfa
1.9. minimization of dfa1.9. minimization of dfa
1.9. minimization of dfaSampath Kumar S
 
1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressions1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressionsSampath Kumar S
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfaSampath Kumar S
 
1.5 & 1.6 regular languages & regular expression
1.5 & 1.6 regular languages & regular expression1.5 & 1.6 regular languages & regular expression
1.5 & 1.6 regular languages & regular expressionSampath Kumar S
 
1.4. finite automaton with ε moves
1.4. finite automaton with ε   moves1.4. finite automaton with ε   moves
1.4. finite automaton with ε movesSampath Kumar S
 
1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automaton1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automatonSampath Kumar S
 
1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton1.3.1 deterministic finite automaton
1.3.1 deterministic finite automatonSampath Kumar S
 
1.2. introduction to automata theory
1.2. introduction to automata theory1.2. introduction to automata theory
1.2. introduction to automata theorySampath Kumar S
 

More from Sampath Kumar S (20)

5.2 primitive recursive functions
5.2 primitive recursive functions5.2 primitive recursive functions
5.2 primitive recursive functions
 
4.7. chomskian hierarchy of languages
4.7. chomskian hierarchy of languages4.7. chomskian hierarchy of languages
4.7. chomskian hierarchy of languages
 
4.6 halting problem
4.6 halting problem4.6 halting problem
4.6 halting problem
 
4.3 techniques for turing machines construction
4.3 techniques for turing machines construction4.3 techniques for turing machines construction
4.3 techniques for turing machines construction
 
4.2 variantsof turing machines (types of tm)
4.2 variantsof turing machines (types of tm)4.2 variantsof turing machines (types of tm)
4.2 variantsof turing machines (types of tm)
 
4.1 turing machines
4.1 turing machines4.1 turing machines
4.1 turing machines
 
3.6 & 7. pumping lemma for cfl & problems based on pl
3.6 & 7. pumping lemma for cfl & problems based on pl3.6 & 7. pumping lemma for cfl & problems based on pl
3.6 & 7. pumping lemma for cfl & problems based on pl
 
3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl3.5 equivalence of pushdown automata and cfl
3.5 equivalence of pushdown automata and cfl
 
3.4 deterministic pda
3.4 deterministic pda3.4 deterministic pda
3.4 deterministic pda
 
3.1,2,3 pushdown automata definition, moves & id
3.1,2,3 pushdown automata   definition, moves & id3.1,2,3 pushdown automata   definition, moves & id
3.1,2,3 pushdown automata definition, moves & id
 
2.7 normal forms cnf & problems
2.7 normal forms  cnf & problems2.7 normal forms  cnf & problems
2.7 normal forms cnf & problems
 
2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammar2.1 & 2.2 grammar introduction – types of grammar
2.1 & 2.2 grammar introduction – types of grammar
 
1.9. minimization of dfa
1.9. minimization of dfa1.9. minimization of dfa
1.9. minimization of dfa
 
1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressions1.8. equivalence of finite automaton and regular expressions
1.8. equivalence of finite automaton and regular expressions
 
1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa1.7. eqivalence of nfa and dfa
1.7. eqivalence of nfa and dfa
 
1.5 & 1.6 regular languages & regular expression
1.5 & 1.6 regular languages & regular expression1.5 & 1.6 regular languages & regular expression
1.5 & 1.6 regular languages & regular expression
 
1.4. finite automaton with ε moves
1.4. finite automaton with ε   moves1.4. finite automaton with ε   moves
1.4. finite automaton with ε moves
 
1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automaton1.3.2 non deterministic finite automaton
1.3.2 non deterministic finite automaton
 
1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton1.3.1 deterministic finite automaton
1.3.1 deterministic finite automaton
 
1.2. introduction to automata theory
1.2. introduction to automata theory1.2. introduction to automata theory
1.2. introduction to automata theory
 

Recently uploaded

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 

Recently uploaded (20)

BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 

CFG Derivations Languages Parse Trees

  • 2. Derivations and Languages  While inferring whether the given input strings belongs to the given CFG, we can have 2 approaches:  Using the rules from body to head (Recursive Inference)  Using the rules from head to body (Derivation) 11/21/2017 Sampath Kumar S, AP/CSE, SECE 2 Derivation using Grammar Recursive Inference Derivation Left Most Derivation Right Most Derivation
  • 3. Recursive Inference:  Here we take string from each variables, concatenate them in proper order and infer that the resulting string is in the language of the variable in the head 11/21/20173 Sampath Kumar S, AP/CSE, SECE
  • 4. Derivation:  Here we use the production from head to body i.e., from start symbol expanding till reaches the given string. This use of grammar is called derivation. 11/21/20174 Sampath Kumar S, AP/CSE, SECE
  • 5. Problems to discuss: 61. For the language L = {wcwR | w (0+1)*} check whether the string 01c10 belongs to the language L or not. Solution: Step 1: For the language L, the productions are S → 0S0 | 1S1 | C Step 2: Derivation S → 0S0 [∵ S → 0S0] → 01E10 [∵ S → 1S1] → 01c10 [∵ S → c] 11/21/2017 Sampath Kumar S, AP/CSE, SECE 5
  • 6. Understanding the Language defined by CFG:  The only way to recognize the language, is to try out various strings from the given production rules.  Then by observing the derived strings, one can find out the language generated from the given CFG. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 6
  • 7. Problems to discuss: 62. Derive ‘a4’ from the grammar G=({S}, {a},P,S) where P: S → aS|ε. 63. Find L(G) and derive the string ‘abbab’ for the grammar G=({S}, {a},P,S) where P: S → aS|bS|a|b. 64. Find L(G) and derive the string ‘abbaaba’ for the grammar G=({S,X}, {a},P,S) where P: S → XaaX, X → aX|bX|ε. 65. Find L(G) for the grammar G=({S,C}, {a,b},P,S) where P is given by S → aCa, C → aCa|b. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 7
  • 8. Leftmost and Rightmost Derivation:  If a word w is generated by a CFG by a certain derivation and at each step in the derivation, a rule of production is applied to the leftmost non terminal in the working string, then this derivation is called leftmost derivation (LMD).  If a word w is generated by a CFG by a certain derivation and at each step in the derivation, a rule of production is applied to the rightmost non terminal in the working string, then this derivation is called rightmost derivation (RMD). 11/21/2017 Sampath Kumar S, AP/CSE, SECE 9
  • 9. Problems to discuss: 66. Consider the CFG ({S,X}, {a,b}, P, S} where productions are S → baXaS|ab, X →Xab|aa. Find the LMD and RMD for the string w=baaaababaab. 67. Consider the CFG S → aB|bA A → a | aS | bAA B → b | bS | aBB Find the LMD and RMD for the string W=aabbabba. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 10
  • 10. Derivation Tree:  A derivation tree or parse tree is an ordered rooted tree that graphically represents the semantic information a string derived from a Context - Free Grammar. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 11
  • 11. Representation Technique  Root vertex − Must be labeled by the start symbol.  Vertex − Labeled by a non-terminal symbol.  Leaves − Labeled by a terminal symbol or ε. If S → x1x2 …… xn is a production rule in a CFG, then the parse tree / derivation tree will be as follows − 11/21/2017 Sampath Kumar S, AP/CSE, SECE 12
  • 12. Approaches for constructing Derivation Tree: There are two different approaches to draw a derivation tree −  Top-down Approach −  Starts with the starting symbol S  Goes down to tree leaves using productions  Bottom-up Approach −  Starts from tree leaves  Proceeds upward to the root which is the starting symbol S 11/21/2017 Sampath Kumar S, AP/CSE, SECE 13
  • 13. Derivation or Yield of a Tree:  The derivation or the yield of a parse tree is the final string obtained by concatenating the labels of the leaves of the tree from left to right, ignoring the Nulls.  However, if all the leaves are Null, derivation is Null. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 14
  • 14. Sentential Form and Partial Derivation Tree:  A partial derivation tree is a sub-tree of a derivation tree/parse tree such that either all of its children are in the sub-tree or none of them are in the sub-tree. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 15
  • 15. Leftmost and Rightmost Derivation of a String  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. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 16
  • 16. Left and Right Recursive Grammars  In a context-free grammar G, if there is a production in the form X → Xa, where X is a non- terminal and ‘a’ is a string of terminals, it is called a left recursive production. The grammar having a left recursive production is called a left recursive grammar.  If in a context-free grammar G, if there is a production is in the form X → aX where X is a non- terminal and ‘a’ is a string of terminals, it is called a right recursive production. The grammar having a right recursive production is called a right recursive grammar. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 17
  • 17. Problems to discuss: 68. Let a CFG G= { {S}, {a, b}, P, S} Where P = S → SS | aSb | ε. Draw derivation tree for the string “abaabb”  One derivation form of the above CFG is S → SS → aSbS → abS → abaSb → abaaSbb → abaabb 11/21/2017 Sampath Kumar S, AP/CSE, SECE 18
  • 18. Problems to discuss: 69. Let any set of production rules in a CFG be X → X+X | X*X |X| a over an alphabet {a}. Find LMD and RMD for string "a+a*a“. 70. Construct Parse tree for the string a*(a+b00) for the following CFG using left and right most derivation. E → A | E + E | E * E | (E) A → a | b |Aa | Ab | A0 | A1 71. Construct Parse tree for the string a*(a+a) for the following CFG using left and right most derivation. E → E + E | E * E | (E) | a 11/21/2017 Sampath Kumar S, AP/CSE, SECE 19
  • 19. Problems to discuss: 72. Generate parse tree for the string 00101 using left and right most derivation for following CFG S → A1B, A → 0A|ε | B → 0B | 1B | ε 73. Generate parse tree for the string babbab using left and right most derivation for following CFG S → aSa | bSb | a |b | ε 11/21/2017 Sampath Kumar S, AP/CSE, SECE 20
  • 20. 11/21/2017 Sampath Kumar S, AP/CSE, SECE 21

Editor's Notes

  1. School of EECS, WSU