FALLSEM2020-21 CSE2002 TH VL2020210106983 Reference Material III 27-Aug-2020 CFGPDANOTES PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 79
At a glance
Powered by AI
The key takeaways from the document are that it discusses concepts related to formal languages like context free grammars, pushdown automata and their properties.

There are 2 ways of language acceptance by a PDA: (i) Acceptance by final state (ii) Acceptance by empty stack

To convert a CFG to a PDA: 1) For each variable A, δ(q,ε,A) ={(q,β) | A → β is a production of P} 2) For each terminal a, δ(q,a,a) = {(q,ε)}.

 Context Free Grammar

 Parse tree and derivation tree


 Ambiguity in grammar and language
 Language of a push down automata
 Equivalence of pushdown automat and context free grammar
 Deterministic push down automata
FORMAL LANGUAGE:

The theory of formal language is used in the field of linguistics – to define valid
sentences and give structural descriptions of sentences. Linguistics wanted to define a formal
grammar (To describe the rules of grammar in the mathematical way) to describe English, would
make language translation using computers easy.

CONTEXT FREE GRAMMAR AND LANGUAGES MAY/JUNE 2007

DEFINITION CFG:

 This is the way of describing language by recursive rules called production. It


consists of set of variables, set of terminal symbols, and a starting variable as well
as the production.
 G = (V,T,P,S)

Where V = variables, T = Terminals, P = productions, S = starting variable.

Eg 1: 𝐺 = (𝑉, 𝑇, 𝑃, 𝑆) 𝑉 = {𝐸} 𝑇 = {+,∗, 𝑖𝑑} 𝑆 = {𝐸}

E => E+E E => E*E E => id

Eg 2:Construct the CFG for the language.

L(G) = {01 1𝑛 / n > 1}

S => 0S1/ ξ

S => 0S1
. .
=> 00S11 .
S=>0S1

=> 000S111
. .
=> 000ξ111 .
S=>ξ

S=>000111
𝐺

CONTEXT FREE LANGUAGE:

 If grammar G = (V,T,P,S) be a context free grammar then the language L(G) is a set of

terminal strings that have derivation from the starting symbol.



L(G) = { w in T / S =>
𝐺
w}
 The language generated by the CFG is called Context Free Language.

1) Find L(G) for the following grammar.

a) S => aSb / ab

S=> aSb
. .
=> aaSbb .
S=>aSb

=> aaaSbbb
. .
=> aaaaSbbbb .
S=>ab
. ∗ .
. .
S=>aaaaaSbbbbb . .
L(G) = { 𝑎𝑛 𝑏𝑛 / n > 1}
𝐺

b) S => aCa

C => aCa / b

S => aCa
. .
=> aaCaa .
C=> aCa
. .
=> aaaCaaa .
C=> b

S => aaabaaa
𝐺
. 𝑛
. .
L(G) = { 𝑎 𝑏 𝑎𝑛 / n > 1} \

DERIVATION:

 It is defined as α =>β where β is derived from the symbol ‘α’ with the grammar ‘G’.
𝐺
 Here, we use the production from head to body (i.e.) from starting root node
expanding

until it reaches the given input string.

(i.e.) R.N => w

Eg:

w=01C10

E => 0E0 / 1E1 / C



E =>01C10
E => 0E0 =>01E10
𝐺
RECURSIVE INFERENCE[USING THE PRODUCTION (OR) RULES WE CAN
DERIVE THE STRING FROM BODY TO HEAD]:

DEFINITION:

Here, we take strings from each variables (or) non-terminals concatenated them in a
proper order and infered that the resulting string in the language of the variable (i.e.) starting

Non-terminal (or) root node of the given grammar.


w = 01C10

1) E=> C
2) E => 0E0
3) E => 1E1

S.NO. STRING INFERED FOR LANGUAGE PRODUCTION USED STRING USED

1 C E E => C -

2 0E0 E E => 0E0 -

3 01E10 E E => 1E1 (2)

4 01C10 E E => C (1) & (3)

REDUCTION METHOD:

w = 01C10
. .
= 01E10 .
E=>C
. .
= 0E0 .
E=>1E1

=E

1) RECURSIVE INFERENCE METHOD:


1) E => I 6) I => b
2) E => E+E 7) I => Ia w=a*(a+b00)
3) E => E*E 8) I => Ib
4) E => (E) 9) I => I0
5) I => a 10) I => I1

V = {E,I} T = {+,*,(,),a,b,0,1} S = {E}


S.NO. STRING INFERED FOR LANGUAGE PRODUCTION USED STRING USED

1 a I I => a -

2 b I I => b -

3 b0 I I => I0

I => b0 (2)

4 b00 I I => I0

I => b00 (3)

5 a E E => I

I => a (1)

6 b00 E E => I

I => I0

I => b00 (4)

7 a+b00 E E => E+E

E => I+I

E => a+b00 (5) & (6)

8 (a+b00) E E => (E)

E => (E+E)

E => (I+I)

E => (a+b00) (7)

9 a*(a+b00) E E => E*E

E => I*E

E => I*(E)

E => I*(E+E)

E => I*(I+I)

E => a*(a+b00)
REDUCTION:

w = a*(a+b00)
. .
= I*(I+I00) .
I=>a, I=>b
. .
= I*(I+I0) .
I=>I0

= I*(I+I)
. .
= E*(E+E) .
E=>I
. .
= E*(E) .
E=>E+E
. .
= E*E .
E=>(E)
. .
=E .
E=>E*E

STRING RECOGNITION IN CFG:

1) Recursive Inference.
2) Derivation.
3) Parse Tree (or) Derivation Tree based on LMD & RMD.

TWO TYPES OF DERIVATION:

1) LEFT MOST DERIVATION.


2) RIGHT MOST DERIVATION.

1) LEFT MOST DERIVATION:

DEFINTION:

If at each step in derivation, a production is applied to the left most variable (or) left

most non-terminal then the derivation method is called left most derivation.

Eg:

w = id+id*id

E => E+E

E => E*E

E => id
E => E+E
. .
E => id+E .
E=>id
. .
E => id+E*E .
E=>E*E
. .
E => id+id*E .
E=>id

E => id+id*id
𝐺

RIGHT MOST DERIVATION:

DEFINITION:
A derivation in which the right most variable is replaced at each step then, the
derivation method is called right most derivation.

Eg:
E => E+E
. .
E => E+E*E .
E=>E*E
. .
E => E+E*id .
E=>id
E => E+id*id
. ∗
E id+id*id
. . =>
𝐺

PARSE TREE (OR) DERIVATION TREE:


Parse tree is a pictorial representation of derivation, where the interior nodes are labeled by
variables (or) non-terminals and leaf nodes are labeled by terminals symbols.
Eg:
w = 01C10
E => 0E0
E => 1E1
E => C

DERIVATION:
E => 0E0
. .
=>01E10 .
E => 1E1
. .
=> 01C10 .
E => C

. ∗
. .
E ⇒ 01C10
PARSE TREE (OR) DERIVATION TREE:

E
0 0
E
1 1

AMBIGUOUS GRAMMAR:

A grammar that produces more than one parse tree (or) derivation tree for some
sentence, then the grammar is said to be an ambiguous grammar.An ambiguous grammar
produces more than one left most derivation (or) more than 1 RMD then, the given grammar is
set to be an ambiguous grammar.

Eg: L.M.D.

E => E+E

E => E*E

E => (E)

E => id

w= id+id*id PARSE TREE:

E => E+E E
. .
E => id+E .
E => id E E
+
E => id+E*E E * E
id
E => id+id*E
id id
E => id+id*id

E => id+id*id
𝑙𝑚𝑑
R.M.D:

E => E+E

=> E+E*E

=> E+E*id

=> E+id*id

=> id+id*id

. ∗
E
. . =>
id+id*id
𝐺

PARSE TREE:

E + E

id E * E

id id
1) For the grammar defined by the productions recognize the following string and also
construct the parse tree.

S => A,B

A =>0A/ξ

B => 0B/1B/ξ

i)(a) w => 1001 PARSE TREE:

S => A1 S
. .
=>A10B .
B => 0B A 1 B

=> A100B ξ 0 B
. .
=> A1001B .
B => 1B 0 B
. .
=> ξ1001B .
A => ξ 1 B
. .
=> 1001ξ .
B => ξ ξ
.
. .
S => 1001

i)(b) w =>1001 PARSE TREE:

S => A1B S
. .
=>ξ1B .
A => ξ A 1 B
. .
=> 10B .
B => 0B ξ B
0
=> 100B B
0
. .
=> 1001B .
B => 1B
. . 1
=> 1001ξ .
B => ξ B

ξ
. ∗
. .
S =>1001
𝐺

ii) w = 00101

S => A1B
. .
=>0A1B .
A => 0A
. .
=> 00A1B .
A => 0A
. .
=> 00ξ1B .
A => ξ

=> 001B
. .
=> 0010B .
B => 0B
. .
=> 00101B .
B =>1B
. .
=> 00101ξ .
B => ξ
. ∗
. .
S => 1001
𝐺
PARSE TREE:

A 1 B

0 A 0 B

0 A 1 B

ξ ξ

iii) w = 00101
S => A1B
. .
=>0A1B .
A => 0A
. .
=> 00A1B .
A => 0A
. .
=> 000A1B .
A => 0A
. .
=> 000ξ1B .
A =>ξ
. .
=> 00011B .
B => 1B
. .
=> 00011ξ .
B => ξ
. ∗
. .
S =>00011
𝐺

PARSE TREE:

A 1 B

A 1 B
0

0 A ξ

0 A

ξ
1) Consider the context free grammar whose productions are:

S => aAS/a

A => SbA /SS/ba


and show that S =>aabbaa and also construct the parse tree.
𝐺

S => aAS
. .
=>aSbAS .
A => SbA
. .
=> aabAS .
A => ba
. .
=> aabbaS .
S => a
. ∗
. .
S => aabbaa
𝐺

PARSE TREE:

S
a A S

S b A
a

b a

2) Find LMD & RMD, parse tree for the following grammar. MAY/JUNE 2007

w = 00110101

S => 0B / 1A

A => 0/0S/1AA

B => 1/1S/0BB

L.M.D:
sdfsadfdsa
S => 0B
. .
=> 0BB .
B => 0BB
. .
=> 001B .
B =>1
. .
=> 0011S .
B => 1S
. .
=> 00110B .
S => 0B
. .
=> 001101S .
B => 1S
. .
=> 0011010B .
S => 0B
. .
=> 00110101 .
B => 1
. ∗
. .
S => 00110101
𝑙𝑚𝑑

PARSE TREE:

0 B

0 B B

1 1 S

0 B

1 S

0 B

1
R.M.D:

S => 0B
. .
=>0BB .
B => 0BB
. .
=> 00B1 .
B => 1
. .
=> 001S1 .
B => 1S
. .
=> 0011A1 .
B => 1A
. .
=> 00110S1 .
A => 0S
. .
=> 001101A1 .
S => 1A
. .
=> 00110101 .
A => 0
. ∗
. .
S => 00110101
𝑟𝑚𝑑

PARSE TREE:

0 B

0 B B

1 S 1
1 A

0 S

1 A

0
3) Find the LMD & RMD for the following ‘G’

S => A1B
W=00101
A => 0A/ξ

B => 0B/1B/ξ
L.M.D.:

S => A1B
. .
=>0A1B .
A=> 0A
. .
=> 00A1B .
A => 0A
. .
=> 00ξ1B .
A => ξ

=> 001B
. .
=> 0010B .
B => 0B
. .
=> 00101B .
B => 1B
. .
=> 00101ξ .
B => ξ
=> 00101
. ∗
. .
S => 00101
𝑙𝑚𝑑

PARSE TREE:

A B
1
0 A 0 B
0 A 1 B

ξ ξ

R.M.D:

S => A1B
. .
=>A10B .
B => 0B
. .
=> A101B .
B => 1B
. .
=> A101ξ .
B => ξ

=> A101
. .
=> 0A101 .
A => 0A
. .
=> 00A101 .
A => 0A
. .
=> 00ξ101 .
A => ξ
. ∗
. .
S => 00101
𝑅𝑀𝐷

PARSE TREE:

A 1 B

0 A 0 B
0 A 1 B

ξ ξ
4) Find LMD, RMD and derivation tree for w = a*b+a*b where ‘G’ is given by

S => S+S / S*S / a / b MAY/JUNE 2007

L.M.D:

S => S+S
. .
=>S*S+S .
S => S*S
. .
=> a*S+S .
S => a
. .
=> a*b+S .
S => b
. .
=> a*b+S*S .
S => S*S
. .
=> a*b+a*S .
S => a
. .
=> a*b+a*b .
S => b
. ∗
. .
S => a*b+a*b
𝐿𝑀𝐷

PARSE TREE:

S + S

S * S S * S

a b a b

R.M.D.:

S => S+S
. .
=>S*S+S .
S => S*S
. .
=> a*S+S .
S => a
. .
=> a*b+S .
S => b
. .
=> a*b+S*S .
S => S*S
. .
=> a*b+a*S .
S => a
. .
=> a*b+a*b .
S => b
. ∗
. .
S => a*b+a*b
𝑅𝑀𝐷

PARSE TREE:

S + S

S * S S * S

a b a b

5) Show that the grammar w = abab is ambiguous. MAY/JUNE 2007

S => a / abSb / aAb

A => bS / aAAb

L.M.D.:

S => abSb
. .
=>abab .
S => a
. ∗
. .
S => abab
𝐿𝑀𝐷

PARSE TREE:

a b S b

a
R.M.D.:

S => aAb
. .
=>abSb .
A => Bs
. .
=> abab .
S => a
. ∗
. .
S => abab
𝐿𝑀𝐷

1) Prove that the given ‘G’ is ambiguous for the string “ w = aababa”

S => aSX / b

X => Xb / a

L.M.D:

S => aSX
. .
=>aaSXX .
S => Asx
. .
=> aabXX .
S => b
. .
=> aabXbX .
X => Xb
. .
=> aababX .
X => a
. .
=> aababa .
X => a
. ∗
. .
S => aababa
𝐿𝑀𝐷

PARSE TREE:

S
a S X

a S X a

X
b b
a

R.M.D.:
S => aSX
. .
=>aSa .
X => a
. .
=> aaSXa .
S => Asx
. .
=> aaSXba .
X => Xb
. .
=> aaSaba .
X => a
. .
=> aababa .
X => a
. ∗
. .
S => aababa
𝑅𝑀𝐷

PARSE TREE:

S
a S X

a S X a

X
b b
a

2) Obtain the string “w = ibtibtaea” from the given production by using LMD.
S => iCtS / iCtSeS / a

C => b
S => iCtS
. .
=>ibtS .
C => b
. .
=> ibtiCtSeS .
S => iCtSeS
. .
=> ibtibtSeS .
C => b
. .
=> ibtibtaeS .
S => a
. .
=> ibtibtaea .
S => a
. ∗
. .
S => ibtibtaea
𝐿𝑀𝐷

PARSE TREE:
S
i C S
t

b i C t S e S

b a a

3) Write a grammar to recognize all prefix expressions involving all binary arithmetic
operators. Construct the parse tree for the sentence “-*+abc/dc” from your
grammar. NOV/DEC 2006

E => -EE
E => *EE
E => +EE
E => /EE
E => a / b / c / d / e

E => -EE
. .
=>-*EEE .
E => *EE
. .
=> -*+EEEE .
E => +EE
. .
=> -*+aEEE .
E => a
. .
=> -*+abEE .
E => b
. .
=> -*+abcE .
E => c
. .
=> -*+abc/EE .
E => /EE
. .
=> -*+abc/dE .
E => d
. .
=> -*+abc/de .
E => e
.
. .
E => -*+abc/de

PARSE TREE:
E

- E E
* E E E E
/

+ E E c d e

a b
4) Write a grammar to recognize all prefix expressions involving all binary arithmetic
operators “-*+xyxy”. NOV/DEC 2006
E => -EE
E => *EE
E => +EE
E => x / y
E => -EE
. .
=>-*EEE .
E => *EE
. .
=> -*+EEEE .
E => +EE
. .
=> -*+xEEE .
E => x
. .
=> -*+xyEE .
E => y
. .
=> -*+xbxE .
E => x
. .
=> -*+xyxy .
E => y
.
. .
E => -*+xyxy

PARSE TREE

E
- E E

* E E y
+ E E
x

x y

5) Show that grammar S => aSbS / bSaS / ξ is ambiguous and also write the
language generated by the given grammar.

S => aSbS

=>aξbS

=> abS

. ∗
. .
S ⇒ab

S => aSbS

=>aaSbSbS

=> aaξbSbS

=> aabξbS

=> aabbξ

. ∗
. .
S ⇒aabb

. 𝑛
. .
L(G) = { 𝑎 𝑏𝑛 / n > 1}

6) Write the CFG for the following CFL L(G) = {𝒂𝒎 𝒃𝒏 𝒄𝒑 / m+n=p, m&n>1}
NOV/DEC 2006
E => aEc / bTc / a /bc

T => bTc / bc

E => aEc
. .
=>aaEcc .
E => aEc
. .
=> aabTccc .
E => bTc
. .
=> aabbcccc .
T => bc
. ∗
. .
E => aabbcccc
𝐿𝑀𝐷

7) Consider the alphabet Σ = { a,b,(,),+,*,-, . ,ξ }. Construct a CFG that generate all the
strings in Σ* that are regular expression on the alphabet, Σ. NOV/DEC 2007
E => E+E
E => E*E
E => (E)
E => E.E
E => E-E
E => a / b / ξ

SENTENTIAL FORM:
DEFINITION:
The string’s are derived from the starting non-terminal is called sentential form.
If grammar G=(V,T,P,S) is a context free grammar, then α in (VUT)* such that
non-terminal δ derives α is a sentential form.

S => α then α is left sentential form.
𝑟𝑚𝑑

S => α then α is right sentential form.
𝑙𝑚𝑑

LEFT MOST DERIVATION

DERIVATION RIGHT MOST DERIVATION PARSE TREE

RECURSIVE INFERENCE

RECURSIVE INFERENCE, DERIVATION, PARSE TREE:

1) The recursive inference determines that terminal string ‘w’ is in the language of variable
‘A’.

2) A ⇒ w

3) A => w
𝑙𝑚𝑑

4) A => 𝑤ξξ
𝑟𝑚𝑑

THEOREM: APR/MAY 2004,NOV/DEC 2005

FROM RECURSIVE INFERENCE TO PARSE TREE:

STATEMENT : Let grammar G = ( V,T,P,S) be a context free grammar if recursive inference


procedure tells that the terminal string w is in the language of the variable ‘A’, then there is a
parse tree (or) derivation tree with root node ‘A’ and yield w.
PROOF:

To prove that if A ⇒ w with zero (or) one (or) more steps then there is a parse tree with
root node ‘A’.

BY INDUCTION HYPOTHESIS METHOD:

1) BASIS STEP: Let the number of steps used to infer the string is 1, then the tree has a single
leaf node it may be either A => 𝑎1 , 𝑎2 , 𝑎3 , … … … … … . 𝑎𝑛 (or) A => ξ.

PARSE TREE:

A A

ξ 𝑎1 𝑎2 … … … 𝑎𝑛

2) INDUCTION STEP:

Let the number of steps used to derive the step is n+1. Assume that there is a parse
tree for all the variables ‘B’ and string ‘x’ is inferred for the non-terminal ‘B’ using n+1 number
of steps. Consider, that the last step of inference that assumes w is the language of the variable
(or) else non-terminal ‘A’ then A => 𝑋1 ,𝑋2 ,……….𝑋𝑘 .. Then each 𝑋𝑖 is either a variable (or)
terminal string. Then, we have to break up the string w having k components such that w having
k components such that w = 𝑤1 ,𝑤2 ,………..𝑤𝑘.

TWO CASES:

1) If 𝑋𝑖 is a terminal, then 𝑤𝑖 = 𝑥𝑖.


2) If 𝑋𝑖 is a variable, then 𝑤𝑖 is a string that was previously infered to be in language L in
atmost ‘n’ steps.

A ⇒ 𝑤1, 𝑤2, ………𝑤𝑘 .

A⇒w
A
𝑥1 𝑥2 ……….. 𝑥𝑘

𝑤1 𝑤2 ……….. 𝑤𝑘

PARSE TREE:

𝑥𝑖 => 𝑤𝑖
𝑥𝑖

𝛼1 𝛼2 ………. 𝛼𝑛

Then, the yield is obtained by concatenating the subtrees from left to right.

For eg: E => E+E

E => E*E

E => id PARSE TREE:

w = id+id*id E

= E+id*id E * E

= E+E*id E + E

= E+E*E
id id
=E

THEOREM:

PARSE TREE TO DERIVATION: NOV/DEC 2004

STATEMENT : Let G = ( V,T,P,S) where G be a context free grammar. Suppose, there is a



parse tree (or) derivation tree with root node ‘A’ and yield ‘w’ (i.e.) A ⇒ 𝑤. Then, there is a left
most derivation for a given grammar ‘G’.

PROOF :

To prove that A => w
𝑙𝑚𝑑

By induction hypothesis method:

1) Basis step.

2) Induction step.

1)BASIS STEP :

If the height of the parse tree is 1, then the parse tree has a root node ‘A’ and yield ‘w’.

A => id
A

w = id

2)INDUCTION STEP:

If the height of the parse tree is n+1. Assume that, there is left most derivative.


A => w
𝑙𝑚𝑑

w

For every parse tree, left most derivation will be A => 𝑥1, 𝑥2 ,………𝑥𝑛 .
𝑙𝑚𝑑

𝑥1 𝑥2 . ………𝑥𝑛 .

𝑤1 𝑤2 𝑤𝑛

TWO CASES:

1) If 𝑋𝑖 is a terminal, then 𝑋𝑖 = 𝑤𝑖 .
2) If 𝑋𝑖 is a variable, then there must be root of some subtrees with yield 𝑤𝑖.
By applying Induction hypothesis, there is a L.M.D.

𝑋𝑖 => 𝑤𝑖
𝐿𝑀𝐷
A => 𝑋1 , 𝑋2 ,……..𝑋𝑘

For each i=1,2,………k.

A => 𝑤1 , 𝑤2 ,……..𝑤𝑖
1) If 𝑋𝑖, is a terminal then there is no need to change any thing.

A => 𝑤1 , 𝑤2 ,……..𝑤𝑘
𝑅𝑀𝐷
2) If 𝑋𝑖, is a variable then derive the string for each 𝑋𝑖, 𝑡𝑜 𝑤𝑖,
=> => => =>
𝑋𝑖 𝐿𝑀𝐷 𝛼1 𝐿𝑀𝐷 𝛼2 ………….𝐿𝑀𝐷 𝛼𝑛 𝐿𝑀𝐷 𝑤𝑖
. ∗
. .
A => 𝑤1 , 𝑤2 ,……..𝑤𝑛
𝐿𝑀𝐷
. ∗
. .
A => w
𝐿𝑀𝐷

For eg:
E => E+E / E*E / id

L.M.D:
E => E+E
=>id+E
=> id+E*E
=> id+id*E
=> id+id*id
.
. .
E => id+id*id

PARSE TREE:

E + E

id E * E

id id
THEOREM:

DERIVATION TO RECURSIVE INFERENCE:



STATEMENT : Let G = (V, T, P, S). Let G be a CFG if there is a derivation A ⇒w with
zero (or) more than 1 step then there is a recursive inference procedure applied to a grammar.
Determine that w is in the language of the variable (or) else non-terminal ‘A’.

By Induction Principle Method (or) hypothesis Method.

PROOF :

By induction hypothesis method:

1) Basis step. 2) Induction step.


1)BASIS STEP :

If the derivation is the single step (i.e.) A ⇒w must be a production.

A ⇒w where, w is in the language of variable ‘A’.

2)INDUCTION STEP:

Suppose the derivation takes ‘n+1’ steps

A => 𝑋1 , 𝑋2 ,……..𝑋𝑘

⇒w

Break w as 𝑤1 , 𝑤2 ,……..𝑤𝑘 where

1) If 𝑋𝑖 is a terminal, then 𝑋𝑖 = 𝑤𝑖 .
2) If 𝑋𝑖 is a variable, then

𝑋𝑖 ⇒ 𝑤𝑖.
A => 𝑋1 , 𝑋2 ,……..𝑋𝑘

A ⇒ 𝑤1 , 𝑤2 ,……..𝑤𝑘


A ⇒w
.
. .
Hence, the theorem is proved.

For eg:

w = 01c10

E => 0E0 /1E1 /c

E => 0E0

=>01E10

=> 01c10

. ∗
. .
E ⇒01c10
APPLICATION OF CFG:

1) Parser [construction of parse tree (or) derivation tree]


2) YACC[Yet Another Compiler to Compiler]
3) Markup Languages[XML & DTD[Document Type Definition]]

INHERENT AMBIGUOUS:

A context free language ‘L’ is said to be an inherendly ambiguous, if all its grammar are
ambiguous.

Eg: S => A/B

w=a A => a

B => a

1) S => A S

S => a A

2) S => B

S => a S
w=aabbccdd

S => AB/C B

A => aAb/ab
a
B => CBd/cd

SC=> AB
=> aCd/aDd
. .
D=>aAbB
=> bDc/bc .
A => Ab
. .
=> aabbB .
A => ab
. .
=> aabbcBd .
B =>cd

. ∗
. .
S ⇒aabbccdd

S => C
. .
=>aCd .
C => aCd
. .
=> aaDdd .
C => aDd
. .
=> aabDcdd .
D =>bDc
. .
=> aabbccdd .
D => bc
.
. .
S => aabbccdd

PUSH DOWN AUTOMATA:


The pushdown automata is essentially a finite automation with control of both an input
tape and a stack on which it can store a string of stack symbols.
With the help of a stack, the pushdown automaton can remember an infinite amount of
information.
a a a b b
Magnetic tape
Top of stack
a
a Finite control
a
b
b
Initial content of stack
Z0

MODEL OF PDA:
o The PDA consists of a finite set of states, a finite set of input symbols and a finite
set of pushdown symbols.
o The finite control has a control of both the input tape and the pushdown store.
o In one transition of the pushdown automaton,
 The control head reads the input symbol, then the go to the new state.
 Replace the symbols at the top of the stack by any string.

TUPLE FORMAT OF PDA:


A pushdown automaton consists of seven tuples,

P=(Q,∑, ├,δ,q0,z0,F)
Where,
Q – A finite non – empty set of states.
∑ - A finite set of inp0ut symbols.
├ – A finite non empty set of stack symbols.
Q0 – q0 in Q is the start state
Z0 – Initial start symbol of the stack;

F –set of accepting states or final states.


δ - The transition function is given by
δ:Q X (∑ U{ξ}) X├  Q X ├*
moves:
The interpretation of
δ(q,a,Z)=(p1,γ1), (p2, γ2), .......... ,(pM, γ M)

where,
q,Pi – sates
a - input symbol
γ i – a symbol in ├*
It is the PDA enters state Pi, replaces the symbol z by the string γi and advances the input
head one symbol. The convention used here is the that the state leftmost symbol of γi will be
placed highest on the stack and the rightmost symbol lowest on the stack.

The implementation of
(q,a,Z)=(p1,γ1), (p2, γ2), .......... ,(pM, γ M)
is that independent of the input symbol being scanned, the pda can enter state pi and replaced Z
by γi for any i,i<=i<=M.Here the input head is not advanced.

INSTANTANEOUS DESCRIPTION (ID)


The ID must record the state and stack contents.
IF M=(Q,∑,T, δ,q0,z0,F) be a PDA, then,
(q,aw,za)├M(p,w,βα) if
δ (q,a,z) = (p,β)
LANGUAGE TO PDA(EMPTY STACK)
1. Convert the PDA for the language { WCWR/(0+1)*} by empty stack
Tuple Format:
PDA N(M)=({ q0,q1,q2},{0,1},δ, |―,q0,z0,q2)
Transition functions:
δ(q0,0,z0) = (q0,0z0)
δ(q0,1,z0) = (q0,1z0) Pushing string into stack
δ(q0,0,0) = (q0,00)
δ(q0,1,1) = (q0,11)
δ(q0,0,1) = (q0,01)
δ(q0,1,0) = (q0,10)
δ(q0,c,0) = (q1,0) Separator and hence only transition of state
δ(q0,c,1) = (q2,1)
δ(q1,0,0) = (q1, ξ)
δ(q1,1,1) = (q1, ξ) Poping string from stack
δ(q1, ξ,z0) = (q2, ξ)
Language acceptance by empty stack
W=100C001

δ(q0,100C001,z0) |―(q0,00C00,1z0)
|―(q0,0C001,01z0)
|―(q0,C001,001z0)
|―(q1,001,001z0)
|―(q1,01,01z0)
|―(q1,1,1z0)
|―(q1, ξ,z0)
δ(q0,100C001,z0) |* (q2, ξ, ξ)

w=01C10

δ(q0,01C10,z0) |―( q0,1C10,0z0)


|―( q0,C10,10z0)
|―( q1,10,10z0)
|―( q1,0,0z0)
|―( q1, ξ,z0)
δ(q0,01C10,z0) |* (q2, ξ, ξ)
w=00C00
δ(q0,00C00,z0) |―(q0,0C00,0z0)
|―(q0,C00,00z0)
|―(q1,00,00z0)
|―(q1,0,0z0)
|―(q1, ξ,z0)

δ(q0,00C00,z0) |* (q2, ξ, ξ)

w=11C11

δ(q0,11C11,z0) |―(q0,1C11,1z0)
|―(q0,C11,11z0)
|―(q1,11,11z0)
|―(q1,1,1z0)
|―(q1, ξ,z0)

δ(q0,11C11,z0) |* (q2, ξ, ξ)

Transition Diagram:

0,z0->oz0

1, z0->1 z0

0,0->00

1,1->11

0,1->01
0,0-> ξ
1,0->10 1,1-> ξ

ξ,z0 -> ξ
Q0 Q1 Q2

C,0 ->0
C,1 ->1
2. Construct the PDA for the language {WWR/(0+1)*} accepted by empty stack
Tuple Format:
PDA N(M)=({ q0,q1,q2},{0,1},δ, |―,q0,z0,q2)

Transition function:

δ(q0,0,z0) = (q0,0z0)
δ(q0,1,z0) = (q0,1z0)
δ(q0,0,0) = (q0,00) or (q1,ξ)
δ(q0,1,1) = (q0,11) or (q1,ξ) Pushing string into stack
δ(q0,0,1) = (q0,01)
δ(q0,1,0) = (q0,10)
δ(q1,0,0) = (q1,ξ)
δ(q1,1,1) = (q1,ξ) Poping string from stack
δ(q1,ξ,z0) = (q2,ξ)
δ(q1,ξ,R) = (q2,ξ)
Language accepted by empty stack

w=0000
δ(q0,0000,z0) |―(q0,000,0z0)
|―(q0,00,00z0)
|―(q1,0,0z0)
|―(q1,ξ,z0)

δ(q0,0000,z0) |* (q2,ξ,ξ)
W=1001
δ(q0,1001,z0) |―(q0,001,1z0)
|―(q0,01,01z0)
|―(q1,1,1z0)
|―(q1,ξ,z0)

δ(q0,1001,z0) |* (q2,ξ,ξ)

w=0110

δ(q0,0110,z0) |―( q0,110,0z0)


|―( q0,10,10z0)
|―( q1,0,0z0)
|―( q1,ξ,z0)
δ(q0,0110,z0) |* (q2,ξ,ξ)
Transition diagram:
0,z0->oz0

1, z0->1 z0

0,0->00

1,1->11

0,1->01

1,0->10
0,0->ξ
1,1-> ξ

Q0 Q1 Q2
ξ,z0 -> ξ
ξ,R ->ξ
0,0 ->ξ
0,1 ->ξ

3.construct the PDA for the language L={anbn/n>=1} accepted by empty stack

Tuple Format:

PDA N(M)=({ q0,q1,q2,q3},{a,b},δ, |―,q0,z0,q3)

Transition function:

δ(q0,a,z0) = (q1,az0) Pushing string into stack


δ(q1,a,a) = (q1,aa)
δ(q1,b,a) = (q2,ξ)
δ(q2,b,a) = (q2,ξ)
δ(q2,ξ,z0) = (q3,ξ) Poping string from stack
Language acceptance by empty stack
for n=2 -> w=aabb
δ(q0,aabb,z0) |―(q1,abb,az0)
|―(q1,bb,aaz0)
|―(q2,b,az0)
|―(q2,ξ,z0)
δ(q0,aabb,z0) |* (q3,ξ,ξ)
for n=4 -> w=aaaabbbb

δ(q0,aaaabbbb,z0) |―(q1,aaabbbb,az0)
|―(q1,aabbbb,aaz0)
|―(q1,abbbb,aaaz0)
|―(q1,bbbb,aaaaz0)
|―(q2,bbb,aaaz0)
|―(q2,bb,aaz0)
|―(q2,b,az0)
|―(q2,ξ,z0)

δ(q0,aaaabbbb,z0) |* (q3,ξ,ξ)

Transition diagram:
a,a->aa b,a ->ξ

a,z0 ->az0 b,a ->ξ ξ,z0 ->ξ


Q0 Q1 Q2 Q3

4. construct the PDA for the language L={ an b2n/n>=1} accepted by empty stack
Tuple Format: NOV/DEC 2007

PDA N(M)=({ q0,q1,q2,q3},{a,b},δ, |―,q0,z0,q3)

Transition function:

δ(q0,a,z0) = (q1,az0)
δ(q1,a,a) = (q1,aa) Pushing string into stack
δ(q1,b,a) = (q2,a)
δ(q2,b,a) = (q1,ξ)
δ(q1,ξ,z0) = (q3,ξ) Poping string from stack

Language acceptance by empty stack

For n=2 -> w=aabbbb

δ(q0,aabbbb,z0) |―(q1,abbbb,az0)
|―(q1,bbbb,aaz0)
|―(q2,bbb,aaz0)
|―(q1,bb,az0)
|―(q2,b,az0)
|―(q1, ξ,z0)

δ(q0,aabbbb,z0) |* (q3,ξ,ξ)

Transition diagram:

a,a->aa
a,z0 ->az0 b,a ->a
Q0 Q1 Q2 Q3

b,a->Ę

Ę,z0 ->Ę

5.construct the PDA for the language L={anbman/n,m >=1} accepted by empty stack

Tuple Format: MAY/JUNE 2007

PDA N(M)=({ q0,q1,q2,q3,q4},{a,b},δ, |―,q0,z0,q4)

Transition function:

δ(q0,a,z0) = (q1,az0)
δ(q1,a,a) = (q1,aa) Pushing string into stack
δ(q1,b,a) = (q2,a)
δ(q2,b,a)= (q2,,a) separator Just a transition in state
δ(q2,a,a) = (q3,ξ)
δ(q3,a,a) = (q3,ξ) Poping string from stack
δ(q3,ξ,z0) = (q4,ξ)

Language acceptance by empty stack

for n=2 and m=3


w=aabbbaa
δ(q0,aabbbaa,z0) |―(q1,abbbaa,az0)
|―(q1,bbbaa,aaz0)
|―(q2,bbaa,aaz0)
|―(q2,baa,aaz0)
|―(q2,aa,aaz0)
|―(q3,a,az0)
|―(q3,ξ,z0)
δ(q0,aabbbaa,z0) |* (q4,ξ,ξ)

Transition diagram:

a,a->aa a,a->ξ
z0 ->az0 b,a ->a a,a ->ξ ξ,z0->ξ
Q0 Q1 Q2 Q3 Q4

6. construct the PDA for the language L={an bmcmdn / n,m >=1} accepted by empty stack

Tuple Format:

PDA N(M)=({ q0,q1,q2,q3,q4,q5},{a,b,c,d},δ, |―,q0,z0,q5)

Transition function:

δ(q0,a,z0) = (q1,az0)
δ(q1,a,a) = (q1,aa)
δ(q1,b,a) = (q2,ba) Pushing string into stack
δ(q2,b,b) = (q2,bb)
δ(q2,c,b) = (q3,ξ)
δ(q3,c,b) = (q3,ξ)
δ(q3,d,a) = (q4,ξ) Poping string from stack
δ(q4,d,a) = (q4,ξ)
δ(q4,ξ,z0) = (q5,ξ)

Language acceptance by empty stack

for n=2 and m=3

w=aabbbcccdd
δ(q0,aabbbcccdd,z0) |―(q1,abbbcccdd,az0)
|―(q1,bbbcccdd,aaz0)
|―(q2,bbcccdd,baaz0)
|―(q2,bcccdd,bbaaz0)
|―(q2,cccdd,bbbaaz0)
|―(q3,ccdd,bbaaz0)
|―(q3,cdd,baaz0)
|―(q3,dd,aaz0)
|―(q4,d,az0)

|―(q4,ξ,z0)

δ(q0,aabbbcccdd,z0) |* (q5,ξ,ξ)

Transition diagram:

d, a-> ξ

a,a->aa b,b->bb c,b-> ξ ξ,z0-> ξ

a,z0->az0 b,a->ba c,b-> ξ , d,a-> ξ


Q0 Q1 Q2 Q3 Q Q
4 5

7. construct the PDA for the language L={ambn c2(m+n)/ n,m >=1} accepted by empty stack

Tuple Format: NOV/DEC 2006

PDA N(M)=({ q0,q1,q2,q3,q4},{a,b,c},δ, |―,q0,z0,q4)

Transition function:

δ(q0,a,z0) = (q1,az0)
δ(q1,a,a) = (q1,aa)
δ(q1,b,a) = (q2,ba) Pushing string into stack
δ(q2,b,b) = (q2,bb)
δ(q2,c,b) = (q3,b)
δ(q2,c,a) = (q3,a)
δ(q3,c,a) = (q2,ξ) Poping string from stack
δ(q2,ξ,z0) = (q4,ξ)
δ(q3,c,b) = (q2,ξ)
Language acceptance by empty stack
m=2 n=3
w=aabbbcccccccccc
δ(q0,aabbbcccccccccc,z0) |―(q1,abbbcccccccccc,az0)
|―(q1,bbbcccccccccc,aaz0)
|―(q2,bbcccccccccc,baaz0)
|―(q2,bcccccccccc,bbaaz0)
|―(q2,cccccccccc,bbbaaz0)
|―(q3,ccccccccc,bbbaaz0)
|―(q2,cccccccc,baaz0)
|―(q3,ccccccc,bbaaz0)
|―(q2,cccccc,baaz0)
|―(q3,ccccc,baaz0)
|―(q2,cccc,aaz0)
|―(q3,ccc,aaz0)
|―(q2,cc,az0)
|―(q3,c,az0)
|―(q2,ξ,z0)

δ(q0,aabbbcccccccccc,z0) |* (q4,ξ,ξ)

Transition diagram:
a,a->aa b,b->bb
c,a ->a
a,z0 ->az0 b,a ->ba c,b ->b
Q0 Q1 Q2 Q3 Q4

c,a ->ξ

c,b->ξ

ξ,z0 ->ξ

8. construct the PDA for the language L={an ba2n / n >=1} accepted by empty stack

Tuple Format:

PDA N(M)=({ q0,q1,q2,q3,q4},{a,b},δ, |―,q0,z0,q4)

Transition function:

δ(q0,a,z0) = (q1,az0)
δ(q1,a,a) = (q1,aa) Pushing string into stack
δ(q2,a,a) = (q3,a)
δ(q1,b,a) = (q2,a) separator Just a transition in state
δ(q3,a,a) = (q2,ξ)
δ(q2,ξ,z0) = (q4,ξ) Poping string from stack

Language acceptance by empty stack


for n=2 -> w=aabaaaa

δ(q0,aabaaaa,z0) |―(q1,abaaaa,az0)
|―(q1,baaaa,aaz0)
|―(q2,aaaa,aaz0)
|―(q3,aaa,aaz0)
|―(q2,aa,az0)
|―(q3,a,az0)
|―(q2,ξ,z0)

δ(q0,aabaaaa,z0) |* (q4,ξ,ξ)

Transition diagram:

a,a->aa

a,z0 ->az0 b,a ->ba a,a ->a


Q0 Q1 Q2 Q3 Q4

a,a->ξ

ξ,z0->ξ

9. construct the PDA for the language L={an+1 b2n / n >=1} accepted by empty stack

Tuple Format:
PDA N(M)=({ q0,q1,q2,q3},{a,b},δ, |―,q0,z0,q3)

Transition function:

δ(q0,a,z0) = (q1,z0) Just a transition of state(skip the first element)


δ(q1,a,z0) = (q1,az0) Pushing string into stack
δ(q1,a,a) = (q1,aa)
δ(q1,b,a) = (q2,a)
δ(q2,b,a) = (q1,ξ)
δ(q1,ξ,z0) = (q3,ξ) Poping string from stack

Language acceptance by empty stack


for n=3 -> w=aaaabbbbbb

δ(q0,aaaabbbbbb,z0) |―(q1,aaabbbbbb,z0)
|―(q1,aabbbbbb,az0)
|―(q1,abbbbbb,aaz0)
|―(q1,bbbbbb,aaaz0)
|―(q2,bbbbb,aaaz0)
|―(q1,bbbb,aaz0)
|―(q2,bbb,aaz0)
|―(q1,bb,az0)
|―(q2,b,az0)
|―(q1,ξ,z0)

δ(q0,aaaabbbbbb,z0) |* (q3,ξ,ξ)

Transition diagram:
a,z0->az0
a,a ->aa
a,z0 ->az0 b,a->a
Q0 Q1 Q2 Q3
b,a->ξ

ξ,z0 ->ξ

10. construct the PDA for the language L={an+2 b2n / n >=1} accepted by empty stack

Tuple Format:
PDA N(M)=({ q0,q1,q2,q3},{a,b},δ, |―,q0,z0,q3)

Transition function:

δ(q0,a,z0) = (q1,z0)
δ(q1,a,z0) = (q2,z0) Just a transition of state
δ(q2,a,z0) = (q2,az0)
δ(q2,a,a) = (q2,aa) Pushing string into stack
δ(q2,b,a) = (q3,a)
δ(q3,b,a) = (q2,ξ)
δ(q2,ξ,z0) = (q4,ξ) Poping string from stack

Language acceptance by empty stack


for n=3 -> w=aaaaabbbbbb

δ(q0,aaaabbbbbb,z0) |―(q1,aaaabbbbbb,z0)
|―(q2,aaabbbbbb,z0)
|―(q2,aabbbbbb,az0)
|―(q2,abbbbbb,aaz0)
|―(q2,bbbbbb,aaaz0)
|―(q3,bbbbb,aaaz0)
|―(q2,bbbb,aaz0)
|―(q3,bbb,aaz0)
|―(q2,bb,az0)

|―(q3,b,az0)

|―(q2,ξ,z0)

δ(q0,aaaabbbbbb,z0) |* (q4,ξ,ξ)

Transition diagram:
a,z0->az0
a,a ->aa
a,z0 ->az0 a,z0 ->az0 Q2 b,a->a Q3 Q4
Q0 Q1

b,a->ξ

ξ,z0 ->ξ
11. construct the PDA for the language L={ambn c(m+n)/ n,m >=1} accepted by empty stack

Tuple Format:

PDA N(M)=({ q0,q1,q2,q3,q4},{a,b,c},δ, |―,q0,z0,q4)

Transition function:

δ(q0,a,z0) = (q1,az0)
δ(q1,a,a) = (q1,aa)
δ(q1,b,a) = (q2,ba) Pushing string into stack
δ(q2,b,b) = (q2,bb)
δ(q2,c,b) = (q3,b)
δ(q2,c,a) = (q3,a)
δ(q3,c,a) = (q2,ξ) Poping string from stack
δ(q3,c,b) = (q2,ξ)
δ(q2,ξ,z0) = (q4,ξ)

Language acceptance by empty stack


m=2 n=3
w=aabbbccccc
δ(q0,aabbbccccc,z0) |―(q1,abbbccccc,az0)
|―(q1,bbbccccc,aaz0)
|―(q2,bbccccc,baaz0)
|―(q2,bccccc,bbaaz0)
|―(q2,ccccc,bbbaaz0)
|―(q3,ccccc,bbbaaz0)
|―(q2,cccc,bbaaz0)
|―(q3, ccc,baaz0)
|―(q2, cc,aaz0)
|―(q3, c,az0)
|―(q2,ξ,z0)

δ(q0,aabbbcccccccccc,z0) |* (q4,ξ,ξ)
Transition diagram:
a,a->aa b,b->bb
c,a ->a
a,z0 ->az0 b,a ->ba c,b ->b
Q0 Q1 Q2 Q3 Q4

c,a ->ξ

c,b->ξ

ξ,z0 ->ξ

LANGUAGE TO PDA(FINAL STATE)


12.construct the PDA for the language L={anbn/n>=1} accepted by Final state

Tuple Format:

PDA N(M)=({ q0,q1,q2 },{a,b},δ, |―,q0,z0,q2)

Transition function:

δ(q0,a,z0) = (q1,az0) Pushing string into stack


δ(q1,a,a) = (q1,aa)
δ(q1,b,a) = (q2,ξ)
δ(q2,b,a) = (q2,ξ)
δ(q2, ξ, z0) = (q3, z0)
Retain the stack element
Language acceptance by empty stack
for n=2 -> w=aabb
δ(q0,aabb,z0) |―(q1,abb,az0)
|―(q1,bb,aaz0)
|―(q2,b,az0)
δ(q0,aabb,z0) |* (q3,ξ, z0)

for n=4 -> w=aaaabbbb

δ(q0,aaaabbbb,z0) |―(q1,aaabbbb,az0)
|―(q1,aabbbb,aaz0)
|―(q1,abbbb,aaaz0)
|―(q1,bbbb,aaaaz0)
|―(q2,bbb,aaaz0)
|―(q2,bb,aaz0)
|―(q2,b,az0)

δ(q0,aaaabbbb,z0) |* (q3,ξ, z0)

Transition diagram:
a,a->aa b,a ->ξ

a,z0 ->az0 b,a ->ξ


Q0 Q1 Q2

13. construct the PDA for the language L={ an b2n/n>=1} accepted by final state
Tuple Format:

PDA N(M)=({ q0,q1,q2 },{a,b},δ, |―,q0,z0,q1)

Transition function:

δ(q0,a,z0) = (q1,az0)
δ(q1,a,a) = (q1,aa) Pushing string into stack
δ(q1,b,a) = (q2,a)
δ(q2,b,a) = (q1,ξ)
Poping string from stack

Language acceptance by final state

For n=2 -> w=aabbbb


δ(q0,aabbbb,z0) |―(q1,abbbb,az0)
|―(q1,bbbb,aaz0)
|―(q2,bbb,aaz0)
|―(q1,bb,az0)
|―(q2,b,az0)

δ(q0,aabbbb,z0) |* (q3,ξ,ξ)

Transition diagram:

a,a->aa
a,z0 ->az0 b,a ->a
Q0 Q1 Q2

b,a->Ę
EQUIVALENCE OF ACCEPTANCE

From Empty stack to final state(Nov/Dec 2003, 2004, 2006)

THEOREM
IF L=N(PN) for some PDA PN = (Q,∑, ├,δ,q0,z0,F)then there is a PDA Pf such that L=L(Pf).

Proof:
The Theorem states that is there is a PDA which has acceptance by empty stack, than there
should be a PDA which also has acceptance by final state.
PN = (Q,∑, ├,δ,q0,z0,F) be a PDA
It is planned to have P f stimulate Pn and find when Pf empties its stack,

Let Pf= (Q,U{q0,qf}∑,├U{x0},δ|,q0 |,x0,{Qf})


Where δ| is given as follows
1. δ1(q0| ,ξ, x0)={(q0,z0, x0)}
2. For all q in Q, a in ∑ U {ξ}, and Z in T, δ|(q,a,z)=(q,a,z)
3. For all q in Q,δ|(q,ξ, x0) contains (qf,ξ)

ξ,x0|ξ

ξ,x0/zo, x0 PN ξ.x0|ξ Qf
Q0

ξ, x0|ξ

To Prove:
W is in L(Pf) if and only if w is in N(Pn).

If Part

(q0 1,w,x0) = ├Pf (q0,w,z0,x0) [Rule 1}


├*(q,E,x0) [Rule 2]
├Pf(qf,ξ ,ξ) [Rule 3}
Since X0 is at the bottom of the stack, conclude
(q0 1, W,x0) ├*(q,ξ,x0) [Rule 2]

Only if part
Rule(1) causes Pn to enter the initial ID of Pf except that Pf will have its own bottom – of-stack
marker Z0. Which is the symbol of Pf’s stack. It is prove that.
(q0,w,z0├*Pn(q,ξ,ξ) That is w is in N(Pn).

FROM FINAL STATE TO EMPTY STATE: APR/MAY 2005,NOV/DEC ‘04/’05


Theorem:
Let L be the L(Pf) for some PDA P f=(Q,∑,T,δ,q0,z0,F) then there is PDA Pn such that
L=N(Pn).

Proof:
Let us simulate Pn from Pf follows.
Pn = (Q,U{qe,qo| }∑,├U{x0},δ|,q0|,x0)
Where δ1 is given as follows
δ1(q01 , ξ , x0) ={(q0,z0,x0)}
δ1(q,a,z) = δ(q,a,z) for all q in q, a in ∑ and z in T

δ1(q,ξ,z) = (qe,ξ) for all in q in F, and z in T U{x0}.


δ1(q,ξ,z0 = (qe,ξ) for all z in T U{x0}
ξ,any| ξ

ξ,any| ξ

Start ξ,x0|zo,xo PfPf Qe


Q0 1
q

ξ,any| ξ
Let x ξ L(Pf). Then(q0,x,x0)├*Pf(q0,x,z0x0)
By rule(2) every move of Pn is a legal move Pf.
(q0,x,z0) ├*Pn(q,ξ,δ)
Since Pn simulates Pf and emptying its stack,

(q0,x,x0) ├*(q0,x,z0x0)
├*(qi,ξ, x0)
├*(qe,ξ)
There fore x ∑ L(Pn)
Next, let us show that if x ∑ L(Pf), then the derivation in Pn must be
(q0 1,x,x0) ├ (q0,x,z0x0)

├*Pn(qi,ξ,γx0)
┬*Pn(qe,ξ)
Since we are using x0 at the bottommost of the stack, we get the derivation by removing x0.
(q0,x,z0)┬(qi,ξ,γ)
And qi is the final state. That is, x ∑ L(Pf).

Equivalence of PDA’s and CFG’s


The three classes of languages are
1. Context free language
2. Language accepted by final state of PDA
3. Language accepted by empty stack of PDA
Are all the same class

Grammar PDA by PDA by final


CFG empty stack state
CONTEXT FREE GRAMMAR TO PDA:
1.Convert the following CFG into PDA using empty stack
S0S1/A
A1A0/S/ ξ

W=0101
PDA N(M)=({q},{0,1}, δ,{0,1,S,A, ξ},qIS,S,qFS}
For non terminals
δ (q, ξ,S)={(q,0S1),(q,A)}
δ (q, ξ,A)={(q,0A1),(q,S)(q, ξ )}
For terminals

δ (q,0,0)=(q, ξ)
δ (q,1,1)= (q, ξ)
δ(q,0101,S) ├ (q,0101,0S1)
├(q,101,S1)
├(q,101,A1)
├(q,101,1A01)

├(q,01,A01)
├(q,01, ξ 01)
├(q,01, 01)
├(q, 1, 1)
δ(q,0101,S) ├*(q, ξ, ξ) Accepted

2. Convert the following CFG into PDA using empty stack(Nov /Dec 07)

SaB/bA
AbAA/aS/a
BaBB/bS/b
For non terminals
δ (q, ξ,S)={(q,aB),(q,bA)}
δ (q, ξ,A)={(q,bAA),(q,aS)(q,a )}
δ (q, ξ,B)={(q,aBB),(q,bS)(q,b )}
For terminals
δ (q,a,a)=(q, ξ)

δ (q,b,b)= (q, ξ)
δ(q,aaabbabbba,S) ├ (q, aaabbabbba,aB)
├(q, aabbabbba,B)
├(q, aabbabbba,aBB)
├(q, abbabbba,BB)
├(q, abbabbba,aBBB)

├(q, bbabbba,BBB)
├(q, bbabbba,bBB)
├(q, babbba,BB)
├(q, babbba,bB)
├(q, abbba,B)
├(q, abbba,aBB)

├(q, bbba,BB)
├(q, bbba,bB)
├(q, bba,bS)
├(q, ba,S)
├(q, ba,bA)
├(q, a,A)

├(q, a,a)
δ(q, aaabbabbba,S) ├*(q, ξ, ξ) Accepted
3. Convert the following CFG into PDA using empty stack
1) E => I 6) I => b
2) E => E+E 7) I => Ia
3) E => E*E 8) I => Ib
4) E => (E) 9) I => I0
5) I => a 10) I => I1

For non terminals

δ (q, ξ,E)={(q,I), (q, E+E) (q, E*E) (q, (E))}


δ (q, ξ,I)={(q,Ia) (q,Ib) (q,I0) (q,I1) (q,b)(q,a )}
For terminals
δ (q,a,a)=(q, ξ)
δ (q,b,b)= (q, ξ)
δ (q,0,0)=(q, ξ)

δ (q,1,1)= (q, ξ)
δ(q,a*(a+b00),E) ├ (q, a*(a+b00),E*E)
├(q, a*(a+b00),I*E)
├(q, a*(a+b00),a*E)
├(q, *(a+b00), *E)
├(q, (a+b00),E)

├(q, (a+b00),(E))
├(q, a+b00), E))
├(q, a+b00), E+E))
├(q, a+b00), I+E))
├(q, a+b00), a+E))
├(q, +b00), +E))
├(q, b00), E))

├(q, b00), I))


├(q, b00), I0))
├(q, b00), I00))
├(q, b00), b00))
├(q,00), 00))
├(q,0), 0))

├(q,),))
δ(q, a*(a+b00),E)├*(q, ξ, ξ) Accepted

4. Convert the following CFG into PDA using empty stack


1) E => id
2) E => E+E
3) E => E*E
4) E => (E)

For non terminals


δ (q, ξ,E)={(q,id), (q, E+E) (q, E*E) (q, (E))}
For terminals
δ (q,id,id)=(q, ξ)
δ (q,+,+)= (q, ξ)
δ (q,*,*)=(q, ξ)

δ (q,(,()= (q, ξ)
δ (q,),))= (q, ξ)
δ(q,(id+id),E) ├ (q, (id+id),(E))
├(q, id+id), E))
├(q,id+id),E+E))
├(q,id+id),id+E))

├(q,+id),+E))
├(q,id),E))
├(q,id),id))
├(q,),))
δ(q, (id+id),E)├*(q, ξ, ξ) Accepted
5. Convert the following CFG into PDA using empty stack
SSbS/a W=ababa
For non terminals
δ (q, ξ,S)={(q,SbS) (q, a) }

For terminals
δ (q,a,a)=(q, ξ)
δ (q,b,b)= (q, ξ)
δ(q,ababa,S) ├ (q,ababa,SbS)
├ (q,ababa,abS)
├ (q,baba,bS)

├ (q,aba,S)
├ (q,aba,SbS)
├ (q,aba,SbS)
├ (q,aba,abS)
├ (q,ba,bS)
├ (q,a,S)

├ (q,a,a)
δ(q, (id+id),E)├*(q, ξ, ξ) Accepted

6.
From CFG to PDA
Let G=(V,T,P,S) be a CFG
Construct the PDA P that accepts L(G) by empty stack as follows.

P=({q},T,VUT,δ,q,S}
WHERE ℓ is defined by
1. For each variable A,
δ(q,ξ,A)={{q,β)|A->B is a production in G}
2. For every terminal symbol a,
δ(q,aa)={(q, ξ)}
THEOREM
“IF PDA is construted from CFG g, then N(P)=L(G).” NOV/DEC 2004
Solution:
IF Part:

Supose W ∑ L(G). Then w has the leftmost derivation


S=γ1=>(lm) γ 2=>(lm)=>............. γ n=w.
Where γi=xi αi
Where xi is a terminal
αi is a string of variables and terminals.
Prove this by induction on i that

(q,w,S)├*(q,yi, αi)
Basis:
If i=1,γ1=S, then
x1=ξ
y1=w
(q,w,s)├*0mov(q,w,s)

Thus basis is proved.


Induction:
If i>n+1
Assume
(q,w,s)├*(q,yi, αi)
yi=>yi+1 involves replacing A by one of its production bodies say β

From the rule(1) it is clear that the PDA POSs. The terminal symbols and replaces the variables
by one its productions in the stack. And rule(2) allows us to match any terminals on the top of
the stack with the next symbol. i.e.,δ(q,aa)={(a,ξ)}
Therefore we get the iD(q,yi+1,αi+1) which gives the value for γi+1
Only if part
Let w ∑ N(P). This implies
If (q,x,A)├*p(q,ξ,ξ) then A=>* x
This is proved by induction on the number of moves of P.
Basis:
If it happens in one or more, then there should be A->€ and w=€, So we have can
conclude
A=>* w.
Induction:

Assume P takes n moves

-----------------------------------------------------------------
B-----------------------------------------------------------------
a
-----------------------------------------------------------------

x1 x2 x3
In the first move, the PDA replaces the variable A by one of its production A->y1 y2.......yk in G.
In the next n-1 moves, the PDA consumes x by popping each of y1,y2,...from the stack one by
one.

Let x=x1,x2,x3....xk such that xi is the portion of the string consumed by p while popping yi.
(qi,xi xi+1.....xk,yi)├*(q,xi+1....xk,ξ)
Since the number of moves required to do it is less than n, we have

yi=>*xi
If, Yi is a terminal, then yi=xi.
A=y1 y2...yk=>*x1y2...yk=>x1x2....xk
Therefore A=>W,
Therfore N(P)CL(G)
Thus the theorem is proved.

From PDA.s to Grammars


Theorem: Let M==(Q,∑,├,δ,q0,z0) be a PDA. Then there is a context free grammar G such that
L(G)=N(M).

Proof:
Let M be the PDA and G=(V,∑,P,S) be a context free grammar, where
1. S is the start symbool
2. V is the set of objects of the form[q,A,P]
Where q and P in Q
A in ├P is the set of productions which are defined as follows.
1.S->[q0,z0,q] for each q in Q

2. [q,A,qM+1]a[q1,B1,q2][q2,B2,q3]....]..[qM,BM,QM+1]
For each a in ∑Uξ
q1,q2......qM+1 in q
a,b1,b2....bM in ┬
Such that
δ(q,a,A) = (q1,B1B2....BM)

if M=0,δ(q,a,A)=(q1,ξ)then
[q,A,q1]a
The variables and productions of G have been defined in such a way that a leftmost
derivation of G have been defined in such a way that a leftmost derivation in G of a sentence x is
a simulation of PDA M when fed the input x.
The variable that appear in any step of a leftmost derivation in G correspond to the
symbol on the stack of M.
The intension is that [q,A,P]derive x if and only if x causes M to erase an A from its stack
by some sequence of moves beginning in state q and ending in state P
To show that L(G)=N(M)

By induction on the number of steps in derivation that


[q,A,p]*x
If and only if (q,x,A)├*(p,ξ,ξ)

If PART:
Basisi
If i=1, then

Δ(q,x,A)=(p,ξ) where x=ξ or single input symbol


Which produces
[q,A,p]x is aproduction of G
Induction
If i>1 and x=ay,then
(q,ay,A)├(q,y1,B1B2…..Bn)

├(q1,y1..yn,B1B2….Bn)
├(q2,y2..yn,B1B2….Bn)
├.
.
.
├(p,ξ,ξ)

Here y=y1 y2…..yn A=B1B2…..Bn


The input symbol yj has the effect of popping Bj from stack after a long sequence of
moves .In general,Bj remains on the stack unchanged while y1,y2……..yj-1 is read
An dalso Q={q1,q2……qn+1} where qn+1=P

Therefore (qj,yj,Bj)├*(qj+1,ξ,ξ)
Thus it produces the production
[qj,Bj,qj+1]yjfor 1≤j≤n
The popping of Bj is shown

If(q,ay,A)├(q1,y,B1B2…Bn)then
[q,A,P]a[q1,B,q2][q2,B2,q3]……[qM,Bn,qn+1]
Therefore [q,A,P]ay1y2….yn=x

Only if part
Suppose [q,A,P]x
This is proved by induction on I the number os steps .

Basis
If i=1 then
[q,x,A]├*(P,ξ,ξ) for i<=j<=n
If we insert Bj+1....Bn at the bottom of each stack in the above sequence of ID’s
(qj,xj,BjBj+1.....Bn)├*(qj+1,ξ,Bj+1....Bn)
From[q,A,P] derivation, we know that

(q,x,a)├*(P,ξ,ξ) for j = 1,2....n


The proof concludes with the observation that
[q,A,P]=>*x with q=q0 and A=z0
[q,z0,P]=>*x if and only if
[q,x,z0]┬*(P,ξ,ξ) for some state P.
That is x is in L(G) if and only if x is in N(M).

PUSH DOWN AUTOMATA TO GRAMMAR


1. Let M=({q0,q1},{0,1},{x, z0},δ,q0, z0,ф) (APR/MAY 05)

Where δ is given by

δ(q0,0, z0) = (q0,0 z0)


δ(q1,1,x) = (q1,ξ)
δ(q0,0,x) = (q0,xx)
δ(q1, ξ ,x) = (q1, ξ)
δ(q0,1,x) = (q1, ξ)
δ(q1, ξ, z0) = (q1, ξ)
Construct a CFG for the PDA ‘M’ T={0,1}
V={S,[q0,x,q0],[q0,x,q1],[q1,x,q0],[q1,x,q1],[q0, z0,q0],[q0, z0,q1],[q1, z0,q0],[q1, z0,q1]}

Productions for starting Non terminal ‘S’

S[q0, z0,q0]/ [q0, z0,q1]


δ(q0,0, z0)=(q0,x z0)

[q0, z0,q0]0[q0,x,q0] [q0, z0,q0]

[q0, z0,q0]0[q0,x,q1] [q1, z0,q0]

[q0, z0,q1]0[q0,x,q0] [q0, z0,q1]

[q0, z0,q1]0[q0,x,q1] [q1, z0,q1]

δ(q0,0,x) = (q0,xx)

[q0,x,q0]0[q0,x,q0] [q0,x,q0]

[q0,x,q0]0[q0,x,q1] [q1,x,q0]

[q0,x,q1]0[q0,x,q0] [q0,x,q1]

[q0,x,q1]0[q0,x,q1] [q1,x,q1]

δ(q0,1,x) = (q1, ξ)

[q0,x,q1]1

[q1,x,q0]No Production

δ(q1, ξ ,x) = (q1, ξ)

[q1,x,q1] ξ

δ(q1, 1 ,x) = (q1, ξ)

[q1,x,q1]1
[q1, z0,q0]No Production

δ(q1, ξ, z0) = (q1, ξ)

[q1, z0,q1] ξ

Eliminating No Production

[q1,x,q0]No Production

[q1, z0,q0]No Production

After Eliminating No Production

S [q0, z0,q0]/[q0, z0,q1]

[q0, z0,q0]0[q0,x,q0] [q0, z0,q0]

[q0, z0,q1]0[q0,x,q0] [q0, z0,q1]

[q0, z0,q1]0[q0,x,q1] [q1, z0,q1]

[q0,x,q0]0[q0,x,q0] [q0,x,q0]

[q0,x,q1]0[q0,x,q0] [q0,x,q1]

[q0,x,q1]0[q0,x,q1] [q1,x,q1]

[q0,x,q1]1

[q1,x,q1]ξ

[q1,x,q1]1

[q1, z0,q1] ξ

Eliminating Unwanted Variables:

S[q0, z0,q0]

[q0, z0,q0]0[q0,x,q0] [q0, z0,q0]

[q0, z0,q1]0[q0,x,q0] [q0, z0,q1]

[q0,x,q0]0[q0,x,q0] [q0,x,q0]

[q0,x,q1]0[q0,x,q0] [q0,x,q1]

After Eliminating the Unwanted Variables:


S[q0, z0,q1]

[q0, z0,q1]0[q0,x,q0] [q0, z0,q1]

[q0,x,q1]0[q0,x,q0] [q0,x,q1]

[q0,x,q1]1

[q1, z0,q1] ξ

[q1,x,q1]ξ

[q1,x,q1]1

[q0,x,q1]0[q0,x,q1][q1,x,q1]

[q0,x,q1]0(1).(1) or 0(1)(ξ)

[q0, z0,q1]0[q0,x,q1][q1, z0,q1]

[q0, z0,q1]0(1)(ξ) or 0(1)(1)(ξ)

S [q0, z0,q1]

S 0(1)(ξ) or 0(1)(1)(ξ)

2. Convert the PDA P={(p,q),{0,1},{x, z0},δ,q, z0} to a CFG if

δ is given by

δ(q,1, z0) = (q,xz0)


δ(q,1,x) = (q,xx)
δ(q,0,x) = (p,xx)
δ(q,ξ , z0) = (q, ξ)
δ(p,1,x) = (p, ξ)
δ(p,0, z0) = (q, z0)

T={0,1}

V={S,[q,x,q],[q,x,p],[p,x,p],[p,x,q],[q, z0,q],[q, z0,p],[p, z0,q],[p, z0,p]}

S[q, z0,q]/ [q, z0,p]

δ(q,1, z0)=(q,x z0)

[q, z0,q]1[q,x,q] [q, z0,q]

[q, z0,q]1[q,x,p] [p, z0,q]


[q, z0,p]1[q,x,q] [q, z0,p]

[q, z0,p]1[q,x,p] [p, z0,p]

δ(q, ξ , z0) = (q, ξ)

[q,x,q] ξ

δ(q,1,x) = (q,xx)

[q,x,q]1[q,x,q] [q,x,q]

[q,x,q]1[q,x,p] [p,x,q]

[q,x,p]1[q,x,q] [q,x,p]

[q,x,p]1[q,x,p] [p,x,p]

δ(q,1,x) = (p, ξ)

[q,x,p] 0[p,x,p]

[q,x,q] 0[p,x,q]

[p,x,q]No Production

δ(p, 1 ,x) = (p, ξ)

[p,x,p]1

δ(p,0,z0)=(q,z0)

[p,z0,q]0[q,z0,q]

[p, z0,p][q,z0,p]

Eliminating No Productions:

[p,x,q]No Production

After Eliminating No Production

S[q, z0,q]/[q, z0,p]

[q, z0,q]1[q,x,q][q, z0,q]

[q, z0,q]1[q,x,p][p, z0,q]/ξ

[q,z0,p]1[q,x,q][q, z0,p]
[q, z0,p]1[q,x,p][q, z0,p]

[q,x,q]1[q,x,q][q,x,q]

[q,x,p]1[q,x,q][q,x,p]

[q,x,p]1[q,x,p][p,x,p]

[q,x,p]0[p,x,p]

[q, z0,q]ξ

[p,x,p]1

[p, z0,q]0[q, z0,q]

[p, z0,p]0[q, z0,p]

After Eliminating Unwanted Variables

S[q, z0,q]

[q, z0,q]1[q,x,p][p, z0,q]

[q, z0,q]ξ

[q,x,p]1[q,x,p][p,x,p]

[q,x,p]0[p,x,p]

[p, z0,q]0[q, z0,q]

[p,x,p]1

[p, z0,q]0[q, z0,q]

[p, z0,q]0(ξ)

[q,x,p]0[p,xp]

[q,x,p]0(1)

[q, z0,q]1[q,x,p][p, z0,q]

[q, z0,q]1(0)(1)(0)(ξ)

S[q, z0,q]1(0)(1)(0) or(ξ)


3. Construct a context free grammar ‘G’ which accepts N(A) where
A=({q0,q1},{a,b},{z0,z},δ,q0,z0,ф),δ is given by

δ(q0,b,z0) = (q0,0z0)

δ(q0,ξ, z0) = (q0,ξ)

δ(q0,b,z) = (q0,zz)

δ(q0, a ,z) = (q1, z)

δ(q0,b,z) = (q1, ξ)

δ(q1, a, z0) = (q0, z0)

T={a,b}

V={S,[q0,z,q0],[q0,z,q1],[q1,z,q0][q1,z,q1],[q0, z0,q0],[q0, z0,q1],[q1, z0,q0],[q1, z0,q1]}

S[q0,z0,q0]/[q0,z0,q1]

δ(q0,b, z0)=(q0,zz0)

[q0, z0,q0]b[q0,z,q0] [q0, z0,q0]

[q0, z0,q0]b[q0,z,q1] [q1, z0,q0]

[q0, z0,q1]b[q0,z,q0] [q0, z0,q1]

[q0, z0,q1]b[q0,z,q1] [q1, z0,q1]

δ(q0,ξ,z0)={(q0,ξ)}
[q0,z0,q0]ξ
δ(q0,b,z)={(q0,zz)}
[q0,z,q0]b[q0,z,q0][q0,z,q0]
[q0,z,q0]b[q0,z,q1][q1,z,q0]
[q0,z,q1]b[q0,z,q0][q0,z,q1]
[q0,z,q1]b[q0,z,q1][q1,z,q1]
δ(q0,a,z)={(q1,z)}
[q0,z,q1]a[q1,z,q1]
[q0,z,q0]a[q1,z,q0]
[q1,z,q0]No Production
δ(q1,b,z)={(q1,ξ)}
[q1,z,q1]b
δ(q1,a,z0)={(q0,z0)}
[q1,z0,q0]a[q0,z0,q0]
[q1,z0,q1a[q0,z0,q1]

Eliminating No Production

[q1,z,q0]No Production

After eliminating No Production

S[q0,z0,q0]/[q0,z0,q1]
[q0,z0,q0]b[q0,z,q0][q0,z0,q0]
[q0,z0,q0]b[q0,z,q1][q1,z0,q0]
[q0,z0,q1]b[q0,z,q0][q0,z0,q1]
[q0,z0,q1]b[q0,z,q1][q1,z0,q1]
[q0,z0,q0]ξ
[q0,z,q0]b[q0,z,q0][q0,z,q0]
[q0,z,q1]b[q0,z,q0][q0,z,q1]
[q0,z,q1]b[q0,z,q1][q1,z,q1]
[q0,z,q1]a[q1,z,q1]
[q1,z,q1]b
[q1,z0,q0]a[q0,z0,q0]
[q1,z0,q1]a[q0,z0,q1]
After eliminating unwanted variables
S[q0,z0,q0]
[q0,z0,q0]b[q0,z,q1][q1,z0,q0]
[q0,z0,q0]ξ
[q0,z,q1]b[q0,z,q1][q1,z,q1]
[q0,z,q1]a[q1,z,q1]
[q1,z0,q0]a[q0,z0,q0]
[q1,z,q1]b
[q1,z0,q0]a[q0,z0,q0]
[q1,z0,q0]a[ξ]
[q0,z0,q1]a[q1,z,q1]
[q0,z,q1]a[b]
[q0,z,q1]b[q0,z,q1][q1,z,q1]
[q0,z,q1]b.a[b][b]
[q0,z0,q0]b[q0,z,q1][q1,z0,q0]
[q0,z0,q0]b.b.a[b][b] a[ξ]
S[q0,z0,q0]
Sξ orb.b.a.[b][b] a[ξ]
CONTEXT FREE LANGUAGE PDAGRAMMAR

NOV/DEC 2006
Construct a PDA accepting {anbman/m,n≥1} by empty stack. Also construct the corresponding
context free grammar accepting the same set.

L={anbman/ m,n≥1}

N=2;m=3 Magnetic tape

a a B b b a a ξ

Stack
a
a
Finite Control
Z0

PDA M=({q0,q1},{a,b},{a,z0},δ,q0,z0,ф)

Where δ is given by

δ(q0,a,z0) = (q1,az0)
δ(q1,a,a) = (q1,aa) Push a’s onto stack
δ(q1,b,a) = (q2,a)
δ(q2,a,a) = (q3,ξ) Read b’s and stack will remain unchanged
δ(q3,a,a) = (q3, ξ)
δ(q3, ξ,z0) = (q4, ξ) Remaining a’s are erased and stack symbol z0 is erased

G=(V,T,P,S) where

V={S,[q0,a,q0],[q0,a,q1],[q1,a,q0],[q1,a,q1],[q0,z0,q0],[q0,z0,q1][q1,z0,q0],[q1,z0,q1]}

T={a,b}

The Production ‘p’ are constructed as follows

S Staffing Non terminal of the constructed grammar

s[q0,z0,q0]/[q0,z0,q1]

δ(q0,a, z0)=(q0,az0)

[q0, z0,q0]a[q0,a,q0] [q0, z0,q0]


[q0, z0,q0]a[q0,a,q1] [q1, z0,q0]

[q0, z0,q1]a[q0,a,q0] [q0, z0,q1]

[q0, z0,q1]a[q0,a,q1] [q1, z0,q1]

δ(q0,a, a)=(q0,aa)

[q0, a,q0]a[q0,a,q0] [q0, a,q0]

[q0, a,q0]a[q0,a,q1] [q1, a,q0]

[q0, a,q1]a[q0,a,q0] [q0,a,q1]

[q0, a,q1]a[q0,a,q1] [q1, a,q1]

δ(q0,b, a)=(q0,a)

[q0, a,q1]b[q1,a,q1]

[q0, a,q0]b[q1,a,q0]

δ(q0,a, a)={(q1,ξ)} And δ(q1,b,a)=(q1,a)

[q1, a,q1]a

[q1, a,q1]b[q1,a,q1]

[q1, a,q0]b[q1,a,q0]

[q1, a,q0]No Production

δ(q!,ξ, z0)={(q1,ξ)}

[q1,z0,q1]ξ

Eliminating No Production

[q1,z0,q0]No Production

After Eliminating No Production

S[q0,z0,q0]/[q0,z0,q1]

[q0,z0,q0]a[q0,a,q0][q0,z0,q0]

[q0,z0,q1]a[q0,a,q0][q0,z0,q1]

[q0,z0,q1]a[q0,a,q0][q0,z0,q1]
[q0,z0,q1]a[q0,a,q1][q1,z0,q1]

[q0,a,q0]a[q0,a,q0][q0,a,q0]

[q0,a,q0]a[q0,a,q1][q1,a,q0]

[q0,a,q1]a[q0,a,q0][q0,a,q1]

[q0,a,q1]a[q0,a,q1][q1,a,q1]

[q0,a,q1]b[q1,a,q1]

[q0,a,q0]b[q1,a,q0]

[q1,a,q1b[q1,a,q1]

[q1,a,q0]b[q1,a,q0]

[q1,z0,q1]ξ

After Eliminating Unwanted Variables,

S[q0,z0,q1]

[q0,z0,q1]a[q0,a,q1][q1,z0,q1]

[q0,a,q1]a[q0,a,q1][q1,a,q1]

[q0,a,q1]b[q1,a,q1]

[q1,a,q1]b[q1,a,q1]

[q1,a,q1]a

[q1,z0,q1]ξ

[q1,a,q1]b[a]

[q0,a,q1]b[a] or b.b[a]

[q0,a,q1]a[q0,a,q1][q1,a,q1]

[q0,a,q1]a.b[a][a]

[q0,z0,q1]a[q0,a,q1][q1,z0,q1]

[q0,z0,q1]ab[a][ξ]

S[q0,z0,q1]
Sa.b[a][ξ]

DETERMINIATIC PUSH DOWN AUTOMATA:

A push down automata M= (Q,∑, ├,δ,q0,z0,F) is said to be deterministic if


1. δ(q,a,b) contains atmost one element.
2. If δ(q,ξ,b) is not empty , then δ(q,c,b) must be empty for every c Є ∑,q Є Q, b Є ├
The first condition says that for any given input symbol and any stack top, atmost one move can
be made.
The second condition says that when a ξ move is possible for some configuration, no input
consuming alternative is available.

Construct a DPDA accepting by an empty stack the language L={anbn/n≥0} or L={0i1i/i≥0}


(or)
Show that set of all strings over {a,b} consisting of equal number of a’s and b’s is accepted
by a Deterministic Push Down Automata. MAY/JUNE 2007
L={anbn/n≥0} or L={0i1i/i≥0}
δ(q0,a,z0) = (q0,az0)
δ(q1,a,a) = (q1,aa)
δ(q1,b,a) = (q2,ξ)
δ(q2, b ,a) = (q2, ξ)
δ(q2, ξ,z0) = (q2, ξ)
for n=2 -> w=aabb
Transition diagram:
a,a->aa b,a -> ξ

a,z0 ->az0 b,a -> ξ ξ,z0 -> ξ


Q0 Q1 Q2 Q3

n=2,aabb
δ(q0,aabb,z0) |―(q1,abb,az0)
|―(q1,bb,aaz0)
|―(q2,b,az0)
|―(q2, ξ,z0)

δ(q0,aabb,z0) |* (q3, ξ, ξ)
Deterministic Push Down Automata:
A PDA is deterministic if it never has a choice of move for
given state, input symbol(including ξ) and a stack symbol(├).Also it never has choice
between making a move using a true input and a move using ξ input.
Language Accepted by DPDA’s:
All the regular languages are accepted (by final state) by
DPDA’s and a there are non regular languages accepted by DPDA’s.
The DPDA languages are CFL and infact languages that
have unambiguous CFG’s .Thus , the DPDA languages lie strictly between the regular
languages and the CFL’s.
TWO MARKS QUESTION AND ANSWERS
1.Let G=({S,C},{a,b},P,S} where P consist of S -> aCa,C->aCa|b.Find L(G).

Solution:

S → aCa

→ aaCaa since C → aCa

→ aiCai

→ an ban since C → b

L(G) = { anban | n>0}

2.Consider G whose productions are S→aAS|a,A→SbA|SS|ba,show that S *=> aabbaa and


construct a derivation tree.

solution:

S → aAS

→ aSbAS Since A → SbA S

→ aabAS Since S → a a A S

→ aabbaS Since A → ba S b A

→ aabbaa Since S → a a b a a

3.Find L(G) ψ where G = ({S},{0,1},{S → 0S1,S → ε},S)

S → 0S1

→ 00S11

.
→ 0n S 1n

S → 0n 1n

Therefore L(G) = {0n1n | n≥0}

4.Define a derivation tree for a CFG.

A derivation tree for a CFG G =(V,T,P,S) is a tree satisfying the following.

 Every vertex has a label , which is a symbol of V U T U ε

 The label of the root is S.

 If a vertex is interior and has label A ,then A must be in V.

 If n has labekl A and vertices n1,n2,….nk are sons of the vertex n


APR/MAY’08,MAY/JUNE’07 ,in order from the left ,with label
x1,x2….xk must be a production in P.

 If vertex n has label λ,then n is a leaf and is the only son of its father.

5.Construct CFG L ={an bn | n≥1}.

Solution:

The productions are

S → aSb | ε , where G = ({s},{a,b,ε},P,S)

6.Find a LM derivation for aaabbabbba with the productions.s

APR/MAY’08,MAY/JUNE’ 07

P: S → aB | bA, A → a|aS|bAA, B→ b|bS|ABB

Solution:

S → aB

S → aaBB

S → aaaBBB

S → aaabbB

S → aaabbaBB

S → aaabbabB
S → aaabbabbS

S → aaabbabbbA

s *→ aaabbabbba

LMD

7.Find L(G) S → aSb, S → ab

S → aSb

→ aaSbb

→ aiSbi

→ ai abbi

→ an bn

L(G) = { an bn | n≥ 1}

8.For the grammer S → aCa, C → aCa/b.Find L(G)

S → aCa

→ aaCaa

→ an C an

S → anban

L(G) = { anban | n >0}

9.Show that id+id*id can be generated by two distinct leftmost derivation in the grammer
-E → E+E|E*E|(E)|id.

(i) E → E+E (ii) E → E*E

→ id +E → E +E*E
→ id + E*E → id + E * E

→ id + id *E → id + id *E

→ id + id*id → id + id * id

10.Define PDA.

A PDA is a finite automaton with extra resource called stack.

P = (Q, ∑ , ┌ , δ ,q0,z0,F)

Where

Q – Finite set of states.

∑ - Finte set of input symbols.

┌ - Finite set of stack symbols.

δ - Transition States.

q0 – Initial state.

z0 - Initial stack symbol.

F – Final state.

11.What are the different ways of language acceptance by a PDA and defin them?

There are 2 ways of language acceptance.

(i) Accepatnce by final state

L(M) = { w |(q0,w,z0) ┌*(p,ε,γ)for some P in F and γ in ┌*}

(ii) Acceptance by empty stack

N(M) = {w | (q0,w,z0) ┌*(p,ε,ε) for some P in Q}

12.consider G = ({A,B},{a,b,c},A,P) with productions.

A → a | aaA | abBc

B → abbA | b

Using the suggested substitution fro the variable B,we get production G^ with
productions.
A → a | aaA | ababbAc | abbc

B → abbA | b

Check whether G^ is equivalent to G by using the string aaabbc.

Solution:

Derive the aabbc using both the grammers G and G1.

(i) using G.

A → aaA

→ aabBc

→ aaabbc

(ii) using G^

A → aaA

→ aaabbc

From this it is clear that the productions of B in G^ is no longer used .Then G^ is


equivalent to G.

13.Write a CFG for the set of strings which does not produce any palindromes.

Solution:

Here the grammer should be designed in such a way that w ≠ wR.

S → aSa | bSb

S→C

C → aAb | bAa A → aA | bA | ε

14.Find the language for the CFG.

S → aSb | aAb

A → bAa

A → ba

Solution:
S → aSb

→ aaSbb

→ anSbn

→ an aAbbn

→ anabAabbn

→ anbmambn

L = { anbmambn , n,m ≥ 1}

15.Find the derivation tree for the grammer.

G = ({S,A,B},{a,b},P,S}

Where P is given by

S → aA | bB

A → ab

B → aBb | a

Solutions:

b A

a b

16.Construct a PDA that accepts the language generated by the grammer

S → aSbb

S → aab

Solution:
The PDA is given by

A = ({q},{a,b},{S,A,B,Z,a,b},δ,q,S}

Where δ is given by

δ(q,z,S)={(q,aABB)}

δ(q,z,A)={(q,aB),{q,a}}

δ(q,z,B)={(q,bA),(a,b)}

δ(q,a,a)={(q,ε)}

δ(q,b,b)={(q,ε)}

18.Defin Parse Tree.

A data structure to represents the source program in a compiler is called Parse Tree.A
parse tree can have nodes and edges.

Eg: a: = b + c

:=

a +

b c

19.Define the language accepted by final state in PDA.

Let P =(Q,∑,┌,δ,q0,z0,F) be a PDA.Then L(P),tha language accepted by P by final state is


L(P) ={w | (q0,w,z0)┌*(q,ε,α)} for some state q in F and any stack string α.

20.How do you covert CFG to PDA.

Let G =({q},T,V U T,δ,q,S) be a CFG.Then Construct a PDA P that accepts L(G) by


empty as follows:

P = ({q},T ,V U T ,δ , q, S)

where δ is given by

1.For each variable A,

δ(q,ε,A) ={(q,β) | A → β is a production of P}

2.For each terminal a,


δ(q,a,a) = {(q,ε)}.

21.Define Deterministic PDA.

A PDA P = (Q,∑,┌,δ,q0,z0,F) to be deterministic if and only if

(i) δ(q,a,X) has at most one member of any q in Q ,a in ∑ or a = ε and X in ┌.

(ii)If δ(q,a,X) is not empty,For some a in ∑ ,then δ(q,ε,X)must be empty.

22.Is it true that non – deterministic PDA is more powerful thatn deterministic
PDA?Justify?

No ,NPDA is not more powerful than DPDA .Because,NPDA may produce ambiguous
grammer by reaching its final state or by emptying its stack.But DPDA produces only
unambiguous grammer.

23.What is the additional feature PDA has when compared with NFA?Is PDA superior
over NFA in the sense of language acceptance? justify?

PDA is superior to NFA by having the following additional features.

 Stack which is used to store the necessary tape symbols and use the state to
remember the conditions.

 Two ways of language acceptances,one by reaching its final state and another by
emptying its stack.

You might also like