Module2 Theory of Computation
Module2 Theory of Computation
Automata
Module 2
March 2, 2022
Learning Objectives and Outcomes
Department of Computer Science and Engineering CFG and PDA March 2, 2022 2/48
Outline
3 Ambiguous Grammar
4 Simplification Forms
5 Properties of CFL
9 Decision Algorithms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 3/48
CFG: Formal Definition
Department of Computer Science and Engineering CFG and PDA March 2, 2022 4/48
CFG: Formal Definition
Context-Free Grammars
Department of Computer Science and Engineering CFG and PDA March 2, 2022 5/48
CFG: Formal Definition
Example:CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 6/48
CFG: Formal Definition
Example:CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 6/48
CFG: Formal Definition
Example:CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 6/48
Derivation and Syntax Trees
Derivation Trees
Trees are used for derivation of CFG.
Definition: A derivation tree (or a parse tree) for a CFG
G = (V , Σ, P, S) is a tree satisfying:
Every vertex has a label which is variable\terminal\∧ .
The root has label S.
The label of the internal vertex is a variable.
If vertices n1 , n2 , .....nk written with labels X1 , X2 , ....Xk are sons of
vertex ’n’ with label A, then A → X1 X2 ...Xk is a production in P.
A vertex ’n’ is a leaf if its label is a ∈ Σ or ∧; ’n’ is the only son of
its father if its label is ∧
Let G = ({S,A},{a,b},P,S) where P consists of
S → aAS\a\SS, A → SbA\ba
Department of Computer Science and Engineering CFG and PDA March 2, 2022 7/48
Derivation and Syntax Trees
Derivation Trees
Derivation Trees
Theorem 1:
∗
Let G=(V,Σ, P, S) be a CFG. Then, S =⇒ α if and only if there
is a derivation tree for G with yield α.
Example: Consider G whose productions are
∗
S → aAS\a, A → SbA\SS\ba. Show that S =⇒ aabbaa and Construct a
derivation tree whose yield is aabbaa.
Department of Computer Science and Engineering CFG and PDA March 2, 2022 9/48
Derivation and Syntax Trees
Derivation Trees
Theorem 1:
∗
Let G=(V,Σ, P, S) be a CFG. Then, S =⇒ α if and only if there
is a derivation tree for G with yield α.
Example: Consider G whose productions are
∗
S → aAS\a, A → SbA\SS\ba. Show that S =⇒ aabbaa and Construct a
derivation tree whose yield is aabbaa.
Case 1:
S =⇒ aAS =⇒ aSbAS =⇒ aabAS =⇒ a2 bbaS =⇒ aabbaa
Department of Computer Science and Engineering CFG and PDA March 2, 2022 9/48
Derivation and Syntax Trees
Derivation Trees
Theorem 1:
∗
Let G=(V,Σ, P, S) be a CFG. Then, S =⇒ α if and only if there
is a derivation tree for G with yield α.
Example: Consider G whose productions are
∗
S → aAS\a, A → SbA\SS\ba. Show that S =⇒ aabbaa and Construct a
derivation tree whose yield is aabbaa.
Case 1:
S =⇒ aAS =⇒ aSbAS =⇒ aabAS =⇒ a2 bbaS =⇒ aabbaa
Case 2:
S =⇒ aAS =⇒ aAa =⇒ aSbAa =⇒ aSbbaa =⇒ aabbaa
Department of Computer Science and Engineering CFG and PDA March 2, 2022 9/48
Derivation and Syntax Trees
Derivation Trees
Theorem 1:
∗
Let G=(V,Σ, P, S) be a CFG. Then, S =⇒ α if and only if there
is a derivation tree for G with yield α.
Example: Consider G whose productions are
∗
S → aAS\a, A → SbA\SS\ba. Show that S =⇒ aabbaa and Construct a
derivation tree whose yield is aabbaa.
Case 1:
S =⇒ aAS =⇒ aSbAS =⇒ aabAS =⇒ a2 bbaS =⇒ aabbaa
Case 2:
S =⇒ aAS =⇒ aAa =⇒ aSbAa =⇒ aSbbaa =⇒ aabbaa
Case 3:
S =⇒ aAS =⇒ aSbAS =⇒ aSbAa =⇒ aabAa =⇒ aabbaa
Department of Computer Science and Engineering CFG and PDA March 2, 2022 9/48
Derivation and Syntax Trees
Derivation Trees
∗
Left most derivation: A derivation A =⇒ w is called
left-most derivation, if we apply production only to the left
most variable at every step.
∗
Right most derivation: A derivation A =⇒ w is a right most
derivation, if we apply production to right most variable at
each step.
Theorem
∗
If A =⇒ w in G , then there is a left most derivation of w .
Department of Computer Science and Engineering CFG and PDA March 2, 2022 10/48
Derivation and Syntax Trees
Derivation Trees
Example: Let G be the grammar S → 0B\1A, A → 0\0S\1AA,
B → 1\1S\0BB. For the string 00110101, find:
the leftmost derivation
the rightmost derivation
The derivation tree
Department of Computer Science and Engineering CFG and PDA March 2, 2022 11/48
Derivation and Syntax Trees
Derivation Trees
Example: Let G be the grammar S → 0B\1A, A → 0\0S\1AA,
B → 1\1S\0BB. For the string 00110101, find:
the leftmost derivation
the rightmost derivation
The derivation tree
Leftmost derivation:
S =⇒ 0B =⇒ 00BB =⇒ 001B =⇒ 0011S =⇒ 02 12 0B =⇒
02 12 01S =⇒ 02 12 010B =⇒ 02 12 0101
Department of Computer Science and Engineering CFG and PDA March 2, 2022 11/48
Derivation and Syntax Trees
Derivation Trees
Example: Let G be the grammar S → 0B\1A, A → 0\0S\1AA,
B → 1\1S\0BB. For the string 00110101, find:
the leftmost derivation
the rightmost derivation
The derivation tree
Leftmost derivation:
S =⇒ 0B =⇒ 00BB =⇒ 001B =⇒ 0011S =⇒ 02 12 0B =⇒
02 12 01S =⇒ 02 12 010B =⇒ 02 12 0101
Rightmost derivation:
S =⇒ 0B =⇒ 00BB =⇒ 00B1S =⇒ 00B10B =⇒ 02 B101S =⇒
02 B1010B =⇒ 02 B10101 =⇒ 02 110101
Department of Computer Science and Engineering CFG and PDA March 2, 2022 11/48
Derivation and Syntax Trees
Derivation Trees
Example: Let G be the grammar S → 0B\1A, A → 0\0S\1AA,
B → 1\1S\0BB. For the string 00110101, find:
the leftmost derivation
the rightmost derivation
The derivation tree
Leftmost derivation:
S =⇒ 0B =⇒ 00BB =⇒ 001B =⇒ 0011S =⇒ 02 12 0B =⇒
02 12 01S =⇒ 02 12 010B =⇒ 02 12 0101
Rightmost derivation:
S =⇒ 0B =⇒ 00BB =⇒ 00B1S =⇒ 00B10B =⇒ 02 B101S =⇒
02 B1010B =⇒ 02 B10101 =⇒ 02 110101
Derivation tree:
Department of Computer Science and Engineering CFG and PDA March 2, 2022 11/48
Ambiguous Grammar
Ambiguity in CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 12/48
Ambiguous Grammar
Ambiguity in CFG
S =⇒ S + S =⇒ a + S =⇒ a + S ∗ S =⇒ a + a ∗ S =⇒ a + a ∗ b
S =⇒ S ∗ S =⇒ S + S ∗ S =⇒ a + S ∗ S =⇒ a + a ∗ S =⇒ a + a ∗ b
Department of Computer Science and Engineering CFG and PDA March 2, 2022 12/48
Ambiguous Grammar
Ambiguity in CFG
Example:
If G is grammar S → SbS|a. Show that the given grammar is
ambigious.
Department of Computer Science and Engineering CFG and PDA March 2, 2022 13/48
Ambiguous Grammar
Ambiguity in CFG
Example:
If G is grammar S → SbS|a. Show that the given grammar is
ambigious.
For w = abababa
Department of Computer Science and Engineering CFG and PDA March 2, 2022 13/48
Ambiguous Grammar
Ambiguity in CFG
Example:
If G is grammar S → SbS|a. Show that the given grammar is
ambigious.
For w = abababa
Department of Computer Science and Engineering CFG and PDA March 2, 2022 13/48
Ambiguous Grammar
Ambiguity in CFG
Example:
If G is grammar S → SbS|a. Show that the given grammar is
ambigious.
For w = abababa
Thus, G is ambiguous.
Department of Computer Science and Engineering CFG and PDA March 2, 2022 13/48
Simplification Forms
Simplification of CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 14/48
Simplification Forms
Those variables which are not deriving any terminal string and
which are not reachable are known as Useless Variables.
Example: S → AB
A → a|B
B → b|C
C → aC
D→b
Department of Computer Science and Engineering CFG and PDA March 2, 2022 15/48
Simplification Forms
Those variables which are not deriving any terminal string and
which are not reachable are known as Useless Variables.
Example: S → AB
A → a|B
B → b|C
C → aC
D→b
C is not deriving any terminal, C is not deriving any terminal
=⇒ useless variable, ∴ remove C
Department of Computer Science and Engineering CFG and PDA March 2, 2022 15/48
Simplification Forms
Those variables which are not deriving any terminal string and
which are not reachable are known as Useless Variables.
Example: S → AB
A → a|B
B → b|C
C → aC
D→b
C is not deriving any terminal, C is not deriving any terminal
=⇒ useless variable, ∴ remove C
S → AB, A → a|B, B → b, D → b
D is not included in S =⇒ remove D
Department of Computer Science and Engineering CFG and PDA March 2, 2022 15/48
Simplification Forms
Those variables which are not deriving any terminal string and
which are not reachable are known as Useless Variables.
Example: S → AB
A → a|B
B → b|C
C → aC
D→b
C is not deriving any terminal, C is not deriving any terminal
=⇒ useless variable, ∴ remove C
S → AB, A → a|B, B → b, D → b
D is not included in S =⇒ remove D
∴ S → AB, A → a|B, B → b
Department of Computer Science and Engineering CFG and PDA March 2, 2022 15/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 16/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 16/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 16/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 17/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 17/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 17/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 17/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 17/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 18/48
Simplification Forms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 18/48
Simplification Forms
Simplifying CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 19/48
Simplification Forms
Simplifying CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 19/48
Simplification Forms
Simplifying CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 19/48
Simplification Forms
Simplifying CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 19/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 20/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 20/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 20/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 20/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 20/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 20/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 20/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 20/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 20/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 21/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 21/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 21/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 21/48
Normal Forms (CNF and GNF)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 21/48
Normal Forms (CNF and GNF)
Linear Grammar
A grammar in which atmost one variable can occur on right
side of any production without restriction on the size of this
grammar, is known as Linear Grammar.
A regular grammar is always linear but not all linear grammars
are regular.
Right Linear Grammar- A grammar G = (V , T , S, P) is said to be
right linear, if all the productions are of the form:
A → xB, A → x
where A, B ∈ V , x ∈ T ∗
Department of Computer Science and Engineering CFG and PDA March 2, 2022 22/48
Normal Forms (CNF and GNF)
Linear Grammar
A grammar in which atmost one variable can occur on right
side of any production without restriction on the size of this
grammar, is known as Linear Grammar.
A regular grammar is always linear but not all linear grammars
are regular.
Right Linear Grammar- A grammar G = (V , T , S, P) is said to be
right linear, if all the productions are of the form:
A → xB, A → x
where A, B ∈ V , x ∈ T ∗
Left Linear Grammar- A grammar is said to be left linear if all the
productions are of the form:
A → Bx, A → x
where A, B ∈ V , x ∈ T ∗
Department of Computer Science and Engineering CFG and PDA March 2, 2022 22/48
Normal Forms (CNF and GNF)
Linear Grammar
A grammar in which atmost one variable can occur on right
side of any production without restriction on the size of this
grammar, is known as Linear Grammar.
A regular grammar is always linear but not all linear grammars
are regular.
Right Linear Grammar- A grammar G = (V , T , S, P) is said to be
right linear, if all the productions are of the form:
A → xB, A → x
where A, B ∈ V , x ∈ T ∗
Left Linear Grammar- A grammar is said to be left linear if all the
productions are of the form:
A → Bx, A → x
where A, B ∈ V , x ∈ T ∗
A regular grammar is one that is either right linear or left
linear
Department of Computer Science and Engineering CFG and PDA March 2, 2022 22/48
Normal Forms (CNF and GNF)
Linear Grammar
A grammar in which atmost one variable can occur on right
side of any production without restriction on the size of this
grammar, is known as Linear Grammar.
A regular grammar is always linear but not all linear grammars
are regular.
Right Linear Grammar- A grammar G = (V , T , S, P) is said to be
right linear, if all the productions are of the form:
A → xB, A → x
where A, B ∈ V , x ∈ T ∗
Left Linear Grammar- A grammar is said to be left linear if all the
productions are of the form:
A → Bx, A → x
where A, B ∈ V , x ∈ T ∗
A regular grammar is one that is either right linear or left
linear
In a regular grammar, atmost one variable appears on right
side of any production. Further, that variable must
consistently be either on rightmost or leftmost symbol of right
side of any production.
Department of Computer Science and Engineering CFG and PDA March 2, 2022 22/48
Normal Forms (CNF and GNF)
Regular Grammar
Department of Computer Science and Engineering CFG and PDA March 2, 2022 23/48
Normal Forms (CNF and GNF)
Regular Grammar
Department of Computer Science and Engineering CFG and PDA March 2, 2022 23/48
Normal Forms (CNF and GNF)
Regular Grammar
Department of Computer Science and Engineering CFG and PDA March 2, 2022 23/48
Normal Forms (CNF and GNF)
Linear Grammar
Department of Computer Science and Engineering CFG and PDA March 2, 2022 24/48
PushDown Automata: Introduction
Pushdown Automata
δ =⇒ Q × (Σ ∪ {∧}) × τ → Q × τ ∗
Each move of the control unit is determined by the current
input symbol as well as by the symbol currently on the top of
the stack.
The result of the move is a new state of control unit and a
change in the top of the stack.
Department of Computer Science and Engineering CFG and PDA March 2, 2022 26/48
PushDown Automata: Introduction
NPDA: Example
Department of Computer Science and Engineering CFG and PDA March 2, 2022 27/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 28/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 29/48
PushDown Automata: Introduction
Department of Computer Science and Engineering CFG and PDA March 2, 2022 30/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 31/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 31/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 31/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 31/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 31/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 31/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 32/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
(q,010000,Z)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
(q,010000,Z) ` (q,010000,SZ)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
(q,010000,Z) ` (q,010000,SZ) ` (q,10000,BB)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
(q,010000,Z) ` (q,010000,SZ) ` (q,10000,BB) ` (q,0000,SB)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
(q,010000,Z) ` (q,010000,SZ) ` (q,10000,BB) ` (q,0000,SB) `
(q,000,BBB)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
(q,010000,Z) ` (q,010000,SZ) ` (q,10000,BB) ` (q,0000,SB) `
(q,000,BBB) ` (q, 00,BB)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
(q,010000,Z) ` (q,010000,SZ) ` (q,10000,BB) ` (q,0000,SB) `
(q,000,BBB) ` (q, 00,BB) ` (q,0,B)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
(q,010000,Z) ` (q,010000,SZ) ` (q,10000,BB) ` (q,0000,SB) `
(q,000,BBB) ` (q, 00,BB) ` (q,0,B) ` (q,λ,Z)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
CFG to PDA
Question Construct a PDA ’A’ equivalent to the following Context
free grammar:
S → 0BB, B → 0S |1S |0.
Test whether 010000 is in N(A).
Solution: Let A =({q},{0,1},{S,B,0,1},δ,q,S,φ)
δ is defined by following rules:
δ(q, λ, Z ) = (q, SZ )
δ(q, 0, S) = (q, BB)
δ(q, 0, B) = (q, S)
δ(q, 1, B) = (q, S)
δ(q, 0, B) = (q, λ)
δ(q, λ, Z ) = (qf , λ)
Let the derivation be:
S → 0BB → 01SB → 010BBB → 010000
Acceptability of 010000:
(q,010000,Z) ` (q,010000,SZ) ` (q,10000,BB) ` (q,0000,SB) `
(q,000,BBB) ` (q, 00,BB) ` (q,0,B) ` (q,λ,Z) ` (qf , λ)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 33/48
Relationship between PDA and CFL
PDA to CFG
1 δ(q0 , a, Z0 )= (q0 , λ)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 34/48
Relationship between PDA and CFL
PDA to CFG
1 δ(q0 , a, Z0 )= (q0 , λ)
[q0 , Z0 , q0 ] → a
Department of Computer Science and Engineering CFG and PDA March 2, 2022 34/48
Relationship between PDA and CFL
PDA to CFG
1 δ(q0 , a, Z0 )= (q0 , λ)
[q0 , Z0 , q0 ] → a
2 δ(q0 , a, Z0 ) = (q0 , aZ0 )
Department of Computer Science and Engineering CFG and PDA March 2, 2022 34/48
Relationship between PDA and CFL
PDA to CFG
1 δ(q0 , a, Z0 )= (q0 , λ)
[q0 , Z0 , q0 ] → a
2 δ(q0 , a, Z0 ) = (q0 , aZ0 )
[q0 Z0 . . .] → a[q0 a . . .][. . . Z0 . . .]
Department of Computer Science and Engineering CFG and PDA March 2, 2022 34/48
Relationship between PDA and CFL
PDA to CFG
1 δ(q0 , a, Z0 )= (q0 , λ)
[q0 , Z0 , q0 ] → a
2 δ(q0 , a, Z0 ) = (q0 , aZ0 )
[q0 Z0 . . .] → a[q0 a . . .][. . . Z0 . . .]
3 δ(q0 , a, Z0 ) = (q1 aXX )
Department of Computer Science and Engineering CFG and PDA March 2, 2022 34/48
Relationship between PDA and CFL
PDA to CFG
1 δ(q0 , a, Z0 )= (q0 , λ)
[q0 , Z0 , q0 ] → a
2 δ(q0 , a, Z0 ) = (q0 , aZ0 )
[q0 Z0 . . .] → a[q0 a . . .][. . . Z0 . . .]
3 δ(q0 , a, Z0 ) = (q1 aXX )
[q0 Z0 . . .] = a[q1 a . . .][. . . X . . .][. . . X . . .]
Department of Computer Science and Engineering CFG and PDA March 2, 2022 34/48
Relationship between PDA and CFL
PDA to CFG
Question: Construct a Context free grammar G which accepts
N(A), where A=({q0 , q1 },{a,b},{Z0 ,Z}, δ, q0 , Z0 , φ) and δ is given
by:
δ(q0 , b, Z0 ) = (q0 , ZZ0 ), δ(q0 , λ, Z0 ) = (q0 , λ)
δ(q0 , b, Z ) = (q0 , ZZ ), δ(q0 , a, Z ) = (q1 , Z )
δ(q1 , b, Z ) = (q1 , λ), δ(q1 , a, Z0 ) = (q0 , Z0 )
Department of Computer Science and Engineering CFG and PDA March 2, 2022 35/48
Relationship between PDA and CFL
PDA to CFG
Question: Construct a Context free grammar G which accepts
N(A), where A=({q0 , q1 },{a,b},{Z0 ,Z}, δ, q0 , Z0 , φ) and δ is given
by:
δ(q0 , b, Z0 ) = (q0 , ZZ0 ), δ(q0 , λ, Z0 ) = (q0 , λ)
δ(q0 , b, Z ) = (q0 , ZZ ), δ(q0 , a, Z ) = (q1 , Z )
δ(q1 , b, Z ) = (q1 , λ), δ(q1 , a, Z0 ) = (q0 , Z0 )
Solution: Let G=(VN , {a, b}, P, S)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 35/48
Relationship between PDA and CFL
PDA to CFG
Question: Construct a Context free grammar G which accepts
N(A), where A=({q0 , q1 },{a,b},{Z0 ,Z}, δ, q0 , Z0 , φ) and δ is given
by:
δ(q0 , b, Z0 ) = (q0 , ZZ0 ), δ(q0 , λ, Z0 ) = (q0 , λ)
δ(q0 , b, Z ) = (q0 , ZZ ), δ(q0 , a, Z ) = (q1 , Z )
δ(q1 , b, Z ) = (q1 , λ), δ(q1 , a, Z0 ) = (q0 , Z0 )
Solution: Let G=(VN , {a, b}, P, S)
VN = {S, [q0 , Z0 , q0 ], [q0 , Z0 , q1 ], [q1 , Z0 , q0 ], [q1 , Z0 , q1 ],
[q0 , Z , q0 ], [q0 , Z , q1 ], [q1 , Z , q0 ], [q1 , Z , q1 ]}
Department of Computer Science and Engineering CFG and PDA March 2, 2022 35/48
Relationship between PDA and CFL
PDA to CFG
Question: Construct a Context free grammar G which accepts
N(A), where A=({q0 , q1 },{a,b},{Z0 ,Z}, δ, q0 , Z0 , φ) and δ is given
by:
δ(q0 , b, Z0 ) = (q0 , ZZ0 ), δ(q0 , λ, Z0 ) = (q0 , λ)
δ(q0 , b, Z ) = (q0 , ZZ ), δ(q0 , a, Z ) = (q1 , Z )
δ(q1 , b, Z ) = (q1 , λ), δ(q1 , a, Z0 ) = (q0 , Z0 )
Solution: Let G=(VN , {a, b}, P, S)
VN = {S, [q0 , Z0 , q0 ], [q0 , Z0 , q1 ], [q1 , Z0 , q0 ], [q1 , Z0 , q1 ],
[q0 , Z , q0 ], [q0 , Z , q1 ], [q1 , Z , q0 ], [q1 , Z , q1 ]}
The Productions are:
Initial: S → [q0 , Z0 , q0 ], [q0 , Z0 , q1 ]
Department of Computer Science and Engineering CFG and PDA March 2, 2022 35/48
Relationship between PDA and CFL
PDA to CFG
Question: Construct a Context free grammar G which accepts
N(A), where A=({q0 , q1 },{a,b},{Z0 ,Z}, δ, q0 , Z0 , φ) and δ is given
by:
δ(q0 , b, Z0 ) = (q0 , ZZ0 ), δ(q0 , λ, Z0 ) = (q0 , λ)
δ(q0 , b, Z ) = (q0 , ZZ ), δ(q0 , a, Z ) = (q1 , Z )
δ(q1 , b, Z ) = (q1 , λ), δ(q1 , a, Z0 ) = (q0 , Z0 )
Solution: Let G=(VN , {a, b}, P, S)
VN = {S, [q0 , Z0 , q0 ], [q0 , Z0 , q1 ], [q1 , Z0 , q0 ], [q1 , Z0 , q1 ],
[q0 , Z , q0 ], [q0 , Z , q1 ], [q1 , Z , q0 ], [q1 , Z , q1 ]}
The Productions are:
Initial: S → [q0 , Z0 , q0 ], [q0 , Z0 , q1 ]
For δ(q0 , b, Z0 ) = (q0 , ZZ0 )
Department of Computer Science and Engineering CFG and PDA March 2, 2022 35/48
Relationship between PDA and CFL
PDA to CFG
Question: Construct a Context free grammar G which accepts
N(A), where A=({q0 , q1 },{a,b},{Z0 ,Z}, δ, q0 , Z0 , φ) and δ is given
by:
δ(q0 , b, Z0 ) = (q0 , ZZ0 ), δ(q0 , λ, Z0 ) = (q0 , λ)
δ(q0 , b, Z ) = (q0 , ZZ ), δ(q0 , a, Z ) = (q1 , Z )
δ(q1 , b, Z ) = (q1 , λ), δ(q1 , a, Z0 ) = (q0 , Z0 )
Solution: Let G=(VN , {a, b}, P, S)
VN = {S, [q0 , Z0 , q0 ], [q0 , Z0 , q1 ], [q1 , Z0 , q0 ], [q1 , Z0 , q1 ],
[q0 , Z , q0 ], [q0 , Z , q1 ], [q1 , Z , q0 ], [q1 , Z , q1 ]}
The Productions are:
Initial: S → [q0 , Z0 , q0 ], [q0 , Z0 , q1 ]
For δ(q0 , b, Z0 ) = (q0 , ZZ0 )
[q0 Z0 . . .] → b[q0 Z . . .][. . . Z0 . . .]
[q0 Z0 . . .] → b[q0 Z . . .][. . . Z0 . . .]
[q0 Z0 . . .] → b[q0 Z . . .][. . . Z0 . . .]
[q0 Z0 . . .] → b[q0 Z . . .][. . . Z0 . . .]
Department of Computer Science and Engineering CFG and PDA March 2, 2022 35/48
Relationship between PDA and CFL
PDA to CFG
Question: Construct a Context free grammar G which accepts
N(A), where A=({q0 , q1 },{a,b},{Z0 ,Z}, δ, q0 , Z0 , φ) and δ is given
by:
δ(q0 , b, Z0 ) = (q0 , ZZ0 ), δ(q0 , λ, Z0 ) = (q0 , λ)
δ(q0 , b, Z ) = (q0 , ZZ ), δ(q0 , a, Z ) = (q1 , Z )
δ(q1 , b, Z ) = (q1 , λ), δ(q1 , a, Z0 ) = (q0 , Z0 )
Solution: Let G=(VN , {a, b}, P, S)
VN = {S, [q0 , Z0 , q0 ], [q0 , Z0 , q1 ], [q1 , Z0 , q0 ], [q1 , Z0 , q1 ],
[q0 , Z , q0 ], [q0 , Z , q1 ], [q1 , Z , q0 ], [q1 , Z , q1 ]}
The Productions are:
Initial: S → [q0 , Z0 , q0 ], [q0 , Z0 , q1 ]
For δ(q0 , b, Z0 ) = (q0 , ZZ0 )
[q0 Z0 q0 ] → b[q0 Zq0 ][q0 Z0 q0 ]
[q0 Z0 q0 ] → b[q0 Zq1 ][q1 Z0 q0 ]
[q0 Z0 q1 ] → b[q0 Zq0 ][q0 Z0 q1 ]
[q0 Z0 q1 ] → b[q0 Zq1 ][q1 Z0 q1 ]
Department of Computer Science and Engineering CFG and PDA March 2, 2022 36/48
Relationship between PDA and CFL
PDA to CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 37/48
Relationship between PDA and CFL
PDA to CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 37/48
Relationship between PDA and CFL
PDA to CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 38/48
Relationship between PDA and CFL
PDA to CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 38/48
Relationship between PDA and CFL
PDA to CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 38/48
Relationship between PDA and CFL
PDA to CFG
For δ(q0 , ∧, Z0 ) = (q0 , ∧)
[q0 Z0 q0 ] → ∧
(q0 , b, Z ) = (q0 , ZZ )
[q0 Zq0 ] → b[q0 Zq0 ][q0 Zq0 ]
[q0 Zq0 ] → b[q0 Zq1 ][q1 Zq0 ]
[q0 Zq1 ] → b[q0 Zq0 ][q0 Zq1 ]
[q0 Zq1 ] → b[q0 Zq1 ][q1 Zq1 ]
For (q0 , a, Z ) = (q1 , Z )
[q0 Zq0 ] → a[q1 Zq0 ]
[q0 Zq1 ] → a[q1 Zq1 ]
Department of Computer Science and Engineering CFG and PDA March 2, 2022 39/48
Relationship between PDA and CFL
PDA to CFG
For δ(q0 , ∧, Z0 ) = (q0 , ∧)
[q0 Z0 q0 ] → ∧
(q0 , b, Z ) = (q0 , ZZ )
[q0 Zq0 ] → b[q0 Zq0 ][q0 Zq0 ]
[q0 Zq0 ] → b[q0 Zq1 ][q1 Zq0 ]
[q0 Zq1 ] → b[q0 Zq0 ][q0 Zq1 ]
[q0 Zq1 ] → b[q0 Zq1 ][q1 Zq1 ]
For (q0 , a, Z ) = (q1 , Z )
[q0 Zq0 ] → a[q1 Zq0 ]
[q0 Zq1 ] → a[q1 Zq1 ]
For δ(q1 , b, Z ) = (q1 , ∧)
[q1 , Z , q1 ] → b
Department of Computer Science and Engineering CFG and PDA March 2, 2022 39/48
Relationship between PDA and CFL
PDA to CFG
For δ(q0 , ∧, Z0 ) = (q0 , ∧)
[q0 Z0 q0 ] → ∧
(q0 , b, Z ) = (q0 , ZZ )
[q0 Zq0 ] → b[q0 Zq0 ][q0 Zq0 ]
[q0 Zq0 ] → b[q0 Zq1 ][q1 Zq0 ]
[q0 Zq1 ] → b[q0 Zq0 ][q0 Zq1 ]
[q0 Zq1 ] → b[q0 Zq1 ][q1 Zq1 ]
For (q0 , a, Z ) = (q1 , Z )
[q0 Zq0 ] → a[q1 Zq0 ]
[q0 Zq1 ] → a[q1 Zq1 ]
For δ(q1 , b, Z ) = (q1 , ∧)
[q1 , Z , q1 ] → b
For δ(q1 , a, Z0 ) → (q0 , Z0 )
[q1 , Z0 , . . .] → a[q0 Z0 . . .]
[q1 , Z0 , . . .] → a[q0 Z0 . . .]
Department of Computer Science and Engineering CFG and PDA March 2, 2022 39/48
Relationship between PDA and CFL
PDA to CFG
For δ(q0 , ∧, Z0 ) = (q0 , ∧)
[q0 Z0 q0 ] → ∧
(q0 , b, Z ) = (q0 , ZZ )
[q0 Zq0 ] → b[q0 Zq0 ][q0 Zq0 ]
[q0 Zq0 ] → b[q0 Zq1 ][q1 Zq0 ]
[q0 Zq1 ] → b[q0 Zq0 ][q0 Zq1 ]
[q0 Zq1 ] → b[q0 Zq1 ][q1 Zq1 ]
For (q0 , a, Z ) = (q1 , Z )
[q0 Zq0 ] → a[q1 Zq0 ]
[q0 Zq1 ] → a[q1 Zq1 ]
For δ(q1 , b, Z ) = (q1 , ∧)
[q1 , Z , q1 ] → b
For δ(q1 , a, Z0 ) → (q0 , Z0 )
[q1 , Z0 , q0 ] → a[q0 Z0 q0 ]
[q1 , Z0 , q1 ] → a[q0 Z0 q1 ]
Department of Computer Science and Engineering CFG and PDA March 2, 2022 40/48
Relationship between PDA and CFL
PDA to CFG
Department of Computer Science and Engineering CFG and PDA March 2, 2022 41/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
where δ is defined by:
δ(q0 , a, Z0 ) = (q0 , aZ0 )
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
where δ is defined by:
δ(q0 , a, Z0 ) = (q0 , aZ0 )
δ(q0 , a, a) = (q0 , aa)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
where δ is defined by:
δ(q0 , a, Z0 ) = (q0 , aZ0 )
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, a) = (q1 , a)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
where δ is defined by:
δ(q0 , a, Z0 ) = (q0 , aZ0 )
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, a) = (q1 , a)
δ(q1 , b, a) = (q1 , a)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
where δ is defined by:
δ(q0 , a, Z0 ) = (q0 , aZ0 )
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, a) = (q1 , a)
δ(q1 , b, a) = (q1 , a)
δ(q1 , a, a) = (q1 , ∧)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
where δ is defined by:
δ(q0 , a, Z0 ) = (q0 , aZ0 )
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, a) = (q1 , a)
δ(q1 , b, a) = (q1 , a)
δ(q1 , a, a) = (q1 , ∧)
δ(q1 , ∧, Z0 ) = (q1 , ∧)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
where δ is defined by:
δ(q0 , a, Z0 ) = (q0 , aZ0 )
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, a) = (q1 , a)
δ(q1 , b, a) = (q1 , a)
δ(q1 , a, a) = (q1 , ∧)
δ(q1 , ∧, Z0 ) = (q1 , ∧)
Let the required grammar G=(VN , {a, b}, P, S)
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
where δ is defined by:
δ(q0 , a, Z0 ) = (q0 , aZ0 )
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, a) = (q1 , a)
δ(q1 , b, a) = (q1 , a)
δ(q1 , a, a) = (q1 , ∧)
δ(q1 , ∧, Z0 ) = (q1 , ∧)
Let the required grammar G=(VN , {a, b}, P, S)
VN =
(S, [q0 Z0 q0 ], [q0 Z0 q1 ], [q1 Z0 q0 ], [q1 Z0 q1 ], q0 aq0 ], [q0 aq1 ], [q1 aq0 ], [q1 aq1 ])
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
PDA to CFG
Example: Construct a PDA accepting {an b m an |m, n ≥ 1} by null
store. Construct the corresponding CFG accepting the same set.
Solution: The PDA ’A’ accepting {an b m an |m, n ≥ 1} is defined as
A=({q0 , q1 },{a,b},{a,Z0 }, δ, q0 , Z0 , φ)
where δ is defined by:
δ(q0 , a, Z0 ) = (q0 , aZ0 )
δ(q0 , a, a) = (q0 , aa)
δ(q0 , b, a) = (q1 , a)
δ(q1 , b, a) = (q1 , a)
δ(q1 , a, a) = (q1 , ∧)
δ(q1 , ∧, Z0 ) = (q1 , ∧)
Let the required grammar G=(VN , {a, b}, P, S)
VN =
(S, [q0 Z0 q0 ], [q0 Z0 q1 ], [q1 Z0 q0 ], [q1 Z0 q1 ], q0 aq0 ], [q0 aq1 ], [q1 aq0 ], [q1 aq1 ])
...
Department of Computer Science and Engineering CFG and PDA March 2, 2022 42/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 43/48
Relationship between PDA and CFL
Let ’L’ be an infinite cotext free language. Then, there exists some
positive integer ’m’ such that any w ∈ L with | w |≥ m can be
decomposed as w=uvxyz with | vxy |≤ m, | vy |≥ 1 such that
uv i xy i z ∈ L for all i=0,1,2,. . . .
Department of Computer Science and Engineering CFG and PDA March 2, 2022 44/48
Relationship between PDA and CFL
Let ’L’ be an infinite cotext free language. Then, there exists some
positive integer ’m’ such that any w ∈ L with | w |≥ m can be
decomposed as w=uvxyz with | vxy |≤ m, | vy |≥ 1 such that
uv i xy i z ∈ L for all i=0,1,2,. . . .
Application:
The punmping lemma is useful for showing that a language
doesnot belong to the family of Context free languages.
Department of Computer Science and Engineering CFG and PDA March 2, 2022 44/48
Relationship between PDA and CFL
Let ’L’ be an infinite cotext free language. Then, there exists some
positive integer ’m’ such that any w ∈ L with | w |≥ m can be
decomposed as w=uvxyz with | vxy |≤ m, | vy |≥ 1 such that
uv i xy i z ∈ L for all i=0,1,2,. . . .
Application:
The punmping lemma is useful for showing that a language
doesnot belong to the family of Context free languages.
Department of Computer Science and Engineering CFG and PDA March 2, 2022 44/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 45/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 45/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 45/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 45/48
Relationship between PDA and CFL
Department of Computer Science and Engineering CFG and PDA March 2, 2022 45/48
Relationship between PDA and CFL
Design Algorithms
Department of Computer Science and Engineering CFG and PDA March 2, 2022 46/48
Questions?
[email protected]
Thank you.