Professional Documents
Culture Documents
Ch-6 CFG, Derivation Trees
Ch-6 CFG, Derivation Trees
UNIVERSITY INSTITUTE OF
ENGINEERING
COMPUTER SCIENCE
ENGINEERING
Bachelor of Engineering
Theory of Computation (CST-353)
Outcome:
• Student will understand the
To know about CFG and its definition
Department of Computer and Science Engineering (CSE)
• S→0S1∣ε
(ε to denote the empty or null string.)
Department of Computer and Science Engineering (CSE)
Example #2
• Language of balanced paranthesis
e.g., ()(((())))((()))….
• CFG?
G:
S => (S) | SS |
How would you “interpret” the string “(((()))()())” using this grammar?
5
Department of Computer and Science Engineering (CSE)
Example #3
• A grammar for L = {0m1n | m≥n}
• CFG?
G:
S => 0S1 | A
A => 0A |
6
Department of Computer and Science Engineering (CSE)
7
Department of Computer and Science Engineering (CSE)
Derivation trees
Example :
Production rules:
•E = E + E
•E = E * E
•E = a | b | c
Input
•a * b + c
Department of Computer and Science Engineering (CSE)
Step 1:
Step 2:
Department of Computer and Science Engineering (CSE)
Step 3:
Step 4:
Department of Computer and Science Engineering (CSE)
Step 5:
Department of Computer and Science Engineering (CSE)
13
Department of Computer and Science Engineering (CSE)
15
Department of Computer and Science Engineering (CSE)
Parse Trees
• Each CFG can be represented using a parse tree:
– Each internal node is labeled by a variable in V
– Each leaf is terminal symbol
– For a production, A==>X1X2…Xk, then any internal node labeled A
has k children which are labeled from X1,X2,…Xk from left to right
X1 … Xi … Xk
16
Examples
Recursive inference
A
E + E
0 A 0
F F
Derivation
1 A 1
a 1
Derivation
Recursive
X1 … Xi … Xk
inference
Derivation Right-most
Recursive
derivation
inference
18
Department of Computer and Science Engineering (CSE)
19
Department of Computer and Science Engineering (CSE)
Outcomes
FAQ :
REFERENCES :
• Martin J.C., “Introduction to Languages and Theory of
Computation”, Tata McGraw-Hill Publising Company
Limited, 3rd Edition.
• Daniel I.A. Cohen, “Introduction to computer Theory”, John
Wiley.
• K.L.P MISHRA, “Introduction to computer Theory” .
• https://youtu.be/NNSK4570Kho
• https://youtu.be/A_Zj-WaA2Lo
THANK YOU