0% found this document useful (0 votes)
27 views21 pages

Flat Unit-5 LM

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views21 pages

Flat Unit-5 LM

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

UNIT – V
CONTEXT FREE GRAMMARS
Objective: To employ with Context Free Grammars and Push-Down Automata

Syllabus:
Ambiguity in context free grammars-definition, examples, Minimization of Context Free
Grammars-removal of useless symbols, ε-productions and unit productions, Chomsky
normal form-definition, examples on conversion of given CFG to CNF, Greibach normal
form-definition, examples on conversion of given CFG to GNF, Pumping Lemma for Context
Free Languages-examples, Enumeration of Properties of CFL (proofs not required)
Applications of CFLs.
Push down automata:
Push down automata, model of PDA, design of PDA, introduction to DCFL and DPDA,
applications of PDA
Outcome: To design PDA’s for the context free languages.

Specific Learning Outcomes:


Bloom's
S. No Learning Outcomes Taxonomy
Level
1 Students will be able to understand ambiguous grammar Understand
2 Students will be able to eliminate null productions Apply
3 Students will be able to eliminate useless symbols Apply
4 Students will be able to eliminate unit productions Apply
5 Students will be able to construct grammars in Chomsky Normal Form Create
6 Students will be able to construct grammar in Greibach Normal Form Create
7 Students will be able to list the enumeration properties of CFLs Remember
8 Students will be able to employ with pumping lemma for CFLs Apply
9 Students will be able to define PDA Understand
10 Students will be able to design PDAs for Context Free Languages Create
11 Students will be able to define DCFL Understand
12 Students will be able to define DPDA Understand
13 Students will be able to list the applications of PDA Remember

DEPARTMENT OF INFORMATION TECHNOLOGY Page 1


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

Derivation Tree: If W is a string in the context free grammar G .W Є L(G).Then the


derivation of W is represented a tree is called derivation tree or parse tree.

In the derivation tree we have

1. The starting sumbol S is the root.


2. All the internal nodes in the parse tree are variable.
3. All the leaf nodes are terminals.
4. If we write all the leaf nodes of the tree from left to right we get a string , that string
is called “Derivation “ or “Yield” of that tree.

Ambiguous Grammar: A Grammar G is said to be ambiguous if there exist a string W


belongs to L(G) has two or more left derivations or two or more right derivations such
grammar is called ambiguous grammar.

Example: AA+A|A-A|a W=a+a-a

Left Most Derivation (LMD) -1 : AA+A Left Most Derivation(LMD) -2 : AA-A


AA+a AA+A-A
Aa+A-A Aa+A-A
Aa+a-A Aa+a-A
Aa+a-a Aa+a-a

A A

A - A
A + A

A + A
a A - A

a a a
a a

Parse Tree for the above derivation: Parse Tree for the above derivation:

There exist two left derivations , So the given grammar is ambiguous.

DEPARTMENT OF INFORMATION TECHNOLOGY Page 2


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

Left Recursion: A grammar is said to be Left recursive if and only if it is of the form AAα
such that A is a variable, and α Є (VUT)*.

Example: SS+S
SSa

Elimination of Left Recursion: Consider the grammar G is in the form

AA α1|A α2....A αn|β1| β2... βm where β1, β2... βn doesn’t starts with A. It is said to be
Left Recursive production. This can be eliminated by introducing the following
productions.

A β1A1| β2A1.......| βmA1

A1 α1 A1| α2A1.......| αnA1| Є

Examples:

1. Consider the CFG SS+S|S*S|a|b eliminate the left recursion if any .


Sol: SS+S|S*S|a|b is in the form of AA α1|A α2....A αn|β1| β2... βm so it is in left
recursion.
After eliminating left recursion, the required grammar is
SaS1|bS1
S1+SS1|*SS1| Є
2. Consider the SAa|b, AAc|Sd| Є eliminate the left recursion if any .
Sol: SAa|b
AAc|Sd| Є
In the production of A replace S with SAa|b then
AAc|Aad|bd| Є
SAa|b
In production A we have Left recursion , so eliminate Left recursion.
AbdA1|A1
A1cA1|adA1| Є
After elimination of left recursion the required Grammar is
SAa|b
AbdA1|A1
A1cA1|adA1| Є

Left Factoring: Two or more productions of a variable A of the grammar G is said to be left
factoring if all the productions of the form
Aα β1| α β2|..... α βn where βi Є(VUT)* and βi doesn’t starts with α then all the
productions are said to have common left factor α example
Sab|ac|ad Here a is called common left factor.

DEPARTMENT OF INFORMATION TECHNOLOGY Page 3


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

Elimination of Left Factoring: Consider the A productions which are having the left
factoring as follows
Aα β1| α β2|..... α βn| γ1| γ2 ......| γm
γ 1, γ2 ........ γm doesn’t starts with α
we can eliminate left factoring in the following way
A αA1| γ1| γ2 ......| γm
A1β1|β2.......βm.
Examples:
1. Consider the CFG SaSa|aa|b eliminate left factoring.
Sol: In the given grammar there exist left factoring . a is common left factoring. We can
eliminate left factoring in following way.
SaA1|b
A1 Sa|a
2. Consider the grammar EE*T|F|E+T|T
TF
Fid eliminate left factoring if any.
Sol: In the given grammar there exist left factoring . ‘id’ is common left factoring.
To eliminate that left factoring we can write the productions as follows.

EidE1
E1*T|+T|id
Tid

Simplification of Grammars:
Grammar may contain some extra symbols , these will increase the length of the grammar.
Elimination of these unnecessary symbols is called simplification of CFGs.
Simplification of grammars generally includes
a. Elimination of useless symbols.
b. Elimination of Є productions.
c. Elimination of unit productions of the form AB.
a. Elimination of useless symbols: A symbol is useless if it can not derive a terminal
or it is not reachable from start symbol.
Examples:

1. Eliminate useless symbols and productions from the following grammar.


SABa|BC, AaC|BCC, Ca, Bbcc, DE, Ed, Fe
Sol: In the given grammar the non terminals D,E,F are not reachable from the start symbol
‘S’, so we can eliminate them And the simplified grammar is
SABa|BC, AaC|BCC, Ca, Bbcc,

DEPARTMENT OF INFORMATION TECHNOLOGY Page 4


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

2. Eliminate useless symbols in G.


SAB|CA, SBC|AB, Aa, CaB|b.

Sol: In the given grammar there is no production for B. So we have to eliminate the
productions which contains B.

The simplified grammar is

SCA
Aa
Cb.

3. Eliminate useless symbols in G. SaAa, AbBB, Bab, Cab.


Sol: In the Given grammar the variable C is not derived from the start symbol ‘S’. So ‘C’ is
useless.
The simplified grammar is
SaAa,
AbBB,
Bab.

b. Elimination of Є productions:
If some CFL contains the word Є then CFG must have a Є-production. However if a
CFG has a Є-production then the CFL doesn’t necessarily contain Є.
Example: SaX
XЄ
CFL={a}
Nullable Variables: In a given Context free grammar a non terminal X is nullable if
1. There is a production XЄ
2. There is a derivation that starts at X and leads to Є
i.e X-----Є

Procedure for eliminating Є – productions:


Step 1: Construct set Vn of all nullable variables.
Step 2: For each production BA, if A is nullable variable, replace nullable variable
by Є and add with all possible combinations on the RHS.
Step 3: Do not add the production Aε .

Examples:

DEPARTMENT OF INFORMATION TECHNOLOGY Page 5


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

1. Eliminate Є-productions from the following grammar G.


SABaC, ABC, Bb|ε, CD|ε, Dd.

Sol: nullable variable are Vn = {B,C,A}


Because B, C are having Є-productions and production A leads to Є.
Now we have to replace the nullable variable with Є.
SABaC|AaC|ABa|aC|a|Aa|Ba
ABC|B|C
CD
Bb
Cd.
2. Eliminate Є-productions from the following grammar G.
SaA, ABB, BaBb|Є

Sol: nullable set Vn= {B}


SaA|a
ABB|B
BaBb|ab.
c. Elimination of unit productions: A production which is of the form AB where A, B
are variables is said to be unit productions.
For each pair of non-terminals A and B such that there is a production AB and the
non-unit productions from B are BS1|S2|...Sn
Where Si Є(TUV)* are strings of terminals and non-terminals then create new
productions as
AS1|S2|...Sn
Do the same for all such pairs A and B simultaneously.

Examples:

1. Eliminate the unit productions in the grammar


SA|bb, AB|b, BS|a

Sol: In the given grammar we have following unit productions


SA, AB, BS.
After eliminating the above unit productions, the required grammar is as follows.
Sb|bb|a
Ab|bb|a
Ba|bb|b

DEPARTMENT OF INFORMATION TECHNOLOGY Page 6


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

2. Eliminate the unit productions in the grammar


SAa|B
BA|bb
Aa|bc|B
Sol: In the given grammar we have following unit productions
SB, BA, AB.
After eliminating the above unit productions, the required grammar is as follows.
SAa|a|bc|bb
Bbb|a|bc
Aa|bc|bb.
Problems:
* Simplify the grammar SaA|aBB, AaAA|Є,BbB|bbC, CB.
Sol: Removing Є-productions gives resulting grammar as
SaA|a|aBB
AaAA|aA|a
BbB|bbc
CB
Eliminating unit productions we get the resulting grammar as
SaA|a|aBB
AaAA|aA|a
BbB|bbc
CbB|bbC
B and C are identified as useless symbols. Eliminate these we get
SaA|a
AaAA|aA|a
Finally the reduced grammar is SaA|a, AaAA|aA|a which defines any number of a’s
Normal Forms:
If G is a Context free grammar and the production of G satisfy certain properties then G is
said to be in a normal form. There are two types of normal forms.
1. Chomsky Normal Form (CNF)
2. Greibach Normal Form (GNF)
1. Chomsky Normal Form (CNF): A grammar G is said to be in a normal form if all the
productions of the form
<variable>  <terminal> (Aa)
<variable>  <variable><variable> (SAB)
Note: CNF allows only a single terminal or two variables on RHS of the each production.
Procedure for Converting CNF:
1. Eliminate null productions and unit productions .
2. Include productions of the form
<variable><variable><variable>
<variable><terminal>.

DEPARTMENT OF INFORMATION TECHNOLOGY Page 7


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

3. Eliminate string of terminals on the right hand side of the productions if it exceeds
one as follows,
for example if we have Sa1a2a3 where a1,a2,a3 are terminals
then introduce a non terminal ‘Cai’ for terminal ai as
Ca1a1
C a2a2
.
.
.
Canan
4. To restrict number of variables in the right hand side introduce new variable and
separate them as follows, suppose we have the production with N non terminals as
shown below
YX1X2X3X4X5
Add N-2 new productions using n-2 new non terminals and modify the productions
as shown in below.
YX1R1
R1X2R2
R2X3R3
R3X4X5
Where Ri are new non terminals.
Note: the languages generated by the new context free grammar is same as the
original context free grammar
Problems:
1. Convert the following CFG to CNF SAB|aB , Aaab|Є , BbbA

Sol: In the given grammar there is Є-production , So we have to eliminate null


production (Є-production) as follows.
SAB|aB|B
Aaab
BbbA|bb.
After the elimination of Є-productions we get a unit production SB , So we have to
eliminate the unit production.
S AB|aB|bbA|bb
Aaab
BbbA|bb
Then SAB already in CNF form.
SbbA
SCbCbA
DCbCb
Cbb
SDA
SCbCb
SCaB
Caa

DEPARTMENT OF INFORMATION TECHNOLOGY Page 8


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

ACaCaCb
ECaCa
AECb
BDA
BCbCb
Then the final production in CNF is
SAB
SDA
SCbCb
SCaB
DCbCb
AECb
ECaCa
BDA
BCbCb
Caa
Cbb
Tuple representation for the grammar:

V=Set of variables={S,A,B,Ca,Cb,D,E}
T= Set of terminals={a,b}
P= productions={ SAB,SDA, SCbCb, SCaB, DCbCb, AECb, ECaCa, ,BDA,
BCbCb , Caa, Cbb}
S= start symbol= S.

2. Greibach Normal Form (GNF):


Let G be the context free grammar, if all the production G of the form Aaα. Where
αЄV* i.e. A GNF grammar allows a single terminal and any number of variables on
R.H.S at the productions.

Example: (i) AaA----valid


(ii) AaAB---valid
(iii) AaAA---valid
(iv) AabAA---not valid

Procedure for Converting GNF:


1. Eliminate null productions , unit productions and useless symbols and construct
CNF.
2. Rename variables as A1, A2, …..with S=A1
3. For each production of the form AiAjα apply the following
(a) If j>i leave the production as it is.
(b) If j=i eliminate left recursion
(c) If j<I apply substitution rule.
4. For each production of the form AiAjα where j>I apply substitution rule if Aj is in
GNF, to bring Ai to GNF.

DEPARTMENT OF INFORMATION TECHNOLOGY Page 9


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

For converting a given grammar to GNF, we need two Lemmas.


Lemma 1: Substitution Rule: Let ABα be a production in P and B is
Bβ1|β2|β3|β4…. The equivalent grammar can be obtained by substituting B in A
then resulting grammar is A β1α|β2α|β3α….

Lemma 2: Elimination of Left Recursion: Consider the grammar G is in the form

AA α1|A α2....A αn|β1| β2... βm where β1, β2... βn doesn’t starts with A. It is said
to be Left Recursive production. This can be eliminated by introducing the following
productions.
A βA1
A  α A1 | Є
1

If we eliminate Є production, then we get


A βA1|β
A1 αA1 | α

Examples on GNF:
1. Convert the following CFG to GNF
SAA|a, ASS|b.

Sol:

STEP 1: There is no Є-productions, unit productions, null productions, already the


grammar is in CNF
STEP 2: Rename variables as A1,A2...i.e S=A1, A=A2 then the production will be

A1A2A2|a----------1

A2A1A1|b----------2
STEP 3:
Take eq 1 A1A2A2|a here j >i so, leave the production as it is

Take eq 2 A2A1A1|b here j < i so, apply substitution rule i.e substitute A 1
production in A2 production.
A2A2A2A1|aA1|b here j = i so, apply left recursion.
A2aA1Z|bZ|aA1|b
ZA2A1Z|A2A1
Substitute A2 in Z then
ZaA1ZA1Z|bA1Z|aA1A1Z|bA1Z|aA1ZA1|bZA1|aA1A1|bA1
STEP 4: Substitute A2 in A1 then
A1aA1ZA2|bZA2|aA1A2|bA2|a
A2aA1Z|bZ|aA1|b

DEPARTMENT OF INFORMATION TECHNOLOGY Page 10


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

Tuple Representation: G(V, T, P, S)


V= {A1, A2, Z}
T= {a,b}
P={ A1aA1ZA2|bZA2|aA1A2|bA2|a , A2aA1Z|bZ|aA1|b,
ZaA1ZA1Z|bA1Z|aA1A1Z|bA1Z|aA1ZA1|bZA1|aA1A1|bA1}.
S=A1.
More problems: 1. Convert the following CFG to GNF SABA, AaA|Є, BbB|Є
2. Convert the following SAB, ABS|b, BSA|a into GNF.
3. Convert the following SS+S|S*S|a|b into GNF.
4. Convert the following SXA|BB, Bb|SB, Xb, Aa.
Pumping Lemma for CFL:
Let L be a CFL, then we find a natural number n such that.
(i) Every ZЄL with |Z|>=n can be written as “UVWXY” for some
strings U, V, W, X, Y.
(ii) |VX|>=1
(iii) |VWX|<=n
(iv) UVKWXKY Є L for all K>=0.
Problems:
1. Prove that L={0n1n2n | n>=1} is not in CFL.
Assume L is in Context free language. Assume L=2. Then
Z=021222=001122 Є L

00 1 1 2 2
U V WXY
For i=2 Pump V,X
UV2WX2Y = 00121222
=021323 does not belongs to L.
There is a contradiction. So our assumption is wrong. Hence given grammar is not
Context free language.
2. Prove that L = {ww|w is bit string} is not in CFL.
Assume L is in Context free language.
Z=0n1n0n1n Є L
UViWXiY Є L
Z=0n 0n 1n 0n 1n
U VWX Y
Pump V, X
Z= 0n 0n+1 1n 0n+1 1n does not belongs to L.
Enumeration properties of CFL:
 Context free languages are closed under substitution , union, concatenation, closure,
positive closure, reversal homomorphism, inverse homomorphism,
 Context free languages are not closed under intersection, difference, and complement.

DEPARTMENT OF INFORMATION TECHNOLOGY Page 11


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

Applications of Context free languages:


 Grammars are useful in specifying syntax of programming languages. They are mainly
used in design of programming languages.
 They are used in natural language processing.
 CFGs are used in speech recognitions also in processing the spoken word.
 The expressive power of CFG is too limited to adequately capture all natural language
phenomena. Therefore extensions of CFG are of interest for computational linguistics.
Push Down Automata:
 The concept of push down automata is useful in the design of parsers or syntax
analyzers.
 The parser verifies the syntax of the text.
 Parsing is a part of the compilation process.
Model of Pushdown Automata:

Control Unit

Z0
Stack
The PDA consists of three components.
1. A input tape
2. A finite control
3. A stack structure
 An input tape consists of a linear configuration of cells each of its contain a character
from the input alphabet.
 The control unit has some pointer (reading head). This points to the current symbol
which is to be read. The head position over the current stack element can read and write
special stack character from that position.
 The stack is also a sequential structure that has a first element and close in either from
the other end.
Formal Definition of PDA:
A finite state push down automata is a seven Tuple M(Q,∑, δ,Γ,F,Z0,q0) where
Q=Finite set of states.
∑=Finite set of Input alphabet
Γ=Finite set of stack alphabet
q0=Initial state
F=Finite set of final state F ⊆ Q
Z0=Initial stack symbol Z0 ∈ Γ
δ=Transition function δ: Q X (∑ U *ε+) X Γ--> Q X Γ*

DEPARTMENT OF INFORMATION TECHNOLOGY Page 12


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

1. PDA has two alphabets


1. an input alphabet ∑ (input string)
2. a stack alphabet Γ(stored on the stack)
2. A move on PDA may indicate
1. an element may added to stack
2. an element may be deleted from
(q, a, Z0)=(q,ε)
q=current state
a=input symbol
Z0=stack symbol
3. they may or may not be change state.
3. They may or may not be change of state.
Example:
1. δ(q0,a, Z0)=( q0, aZ0) indicates that in the state q0 on seeing a, a is pushed onto the
stack. There is no change of state.
2. δ(q0,a, Z0)=( q0, ε) indicates that in the state q0 on seeing a, the current top symbol Z0
is deleted from stack. There is no change of state.
3. δ(q0,a, Z0)=( q1, aZ0) indicates that a is pushed onto the stack and state is changed to q1

Graphical Representation of PDA:


Let M(Q,∑, δ,Γ,F,Z0,q0) be a PDA where Q=*p,q+, ∑=*a,b,c+, F=*a,b+, q0=q, F={p} and δ is
given as follows:
δ(q,a,ε)=(q,a), δ(q,a,a)=(q,aa)
δ(q,b,ε)=(q,b) δ(q,b,b)=(q,bb)
δ(q,c,ε)=(p,ε)
δ(p,a,a)=(p,ε)
δ(p,b,b)=(p,ε)

Instantaneous Description of PDA-String Processing :


W=ababcbab
δ(q,ababcbab,ε) ⟹ δ(q,babcbab, a)
⟹ δ(q,abcbab,ba)
⟹ δ(q,bcbab,aba)
⟹ δ(q,cbab,baba)
⟹ δ(p,bab,baba)
⟹ δ(p,ab.aba)
⟹ δ(p,b,ba)
⟹ δ(p,ε,a)
At this point the input string exhausted and the computation stops. We can not
accepts the original string. Even we are in accept state because stack is not empty.

DEPARTMENT OF INFORMATION TECHNOLOGY Page 13


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

Language accepted by PDA:


A language can be accepted by a pushdown automata using two approaches
1. Acceptance by Final State: The PDA accepts its input by consuming it and finally it
enters in the final state.
2. Acceptance by empty stack: On reading the input string from the initial
configuration for some PDA the stack of PDA becomes empty.( Empty input & stack
empty)
Design of Push Down Automata:
1. Design a PDA which accepts L={anbn| n>=1}
Strings generated by language L={ab,aabb,aaabbb,aaaabbbb,....................}
δ(q0,a,Z0)=(q0,aZ0)
δ(q0,a,a)=( q0,aa)
δ(q0,b,a)=( q1,ε)
δ(q1,b,a)=( q1,ε)
δ(q1,ε, Z0)=( q2, Z0)

2. Design PDA which accepts equal number of a's and b's over ∑=*a,b+
δ(q0,a,Z0)=(q0,aZ0)
δ(q0,a,a)=( q0,aa)
δ(q0,b, Z0)=( q0,b Z0)
δ(q0,b,a)=( q0,ε)
δ(q0,a,b)=( q0,ε)
δ(q0,b,a)=( q0,ε)
δ(q0,ε, Z0)=( q1, Z0)

DEPARTMENT OF INFORMATION TECHNOLOGY Page 14


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

Deterministic PDA:
 The PDA that has one choice of move in any state is called deterministic PDA.
A PDA P={ Q,∑, δ,Γ,F,Z,q0} is deterministic if and only if
1. δ(q,a,X) has atmost one number of q ∈a, a∈ Z or a=ε and X∈Γ.
2. if δ(q,a,X) is not empty for some a∈∑ then δ(q,ε,X) must be empty
 DPDA is less powerful than NPDA
 The context free languages could be recognized by NPDA.

Deterministic Context Free Languages:


 The class of language accepted by DPDA is in between that of regular language and
CFL.
 This language is called deterministic context free languages and it is that subset of
language accepted by NPDA.
 DCFLs are closed under union, concatenation, Kleene closure and complement.

Note: CFL's are not closed under complementation But DCFL's are closed . Hence if the
CFL's is formed to be closed under complement then it is DCFL.

DEPARTMENT OF INFORMATION TECHNOLOGY Page 15


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

Context Free Grammar


Assignment-Cum-Tutorial Questions

Section A: Objective Questions


1. A context free language is called ambiguous if [ ]
a) It has two or more leftmost derivations for some terminal string ѡ є L (G)
b) It has two or more leftmost derivations for some terminal string ѡ є L (G)
c) Both (a) and (b)
d) None of these

2. Which of the following statement is false? [ ]


a) The context free language can be converted into Chomsky normal form
b) The context free language can be converted into Greibach normal form
c) The context free language is accepted by pushdown automata
d) None of these

3. The language L={0ᵐ1ᵐ0ᵐ| m ≥ 1+ is a [ ]


a) Regular language b) Context free language
c) Both (a) and (b) d) None of these

4. While converting the context free grammar into Greibach normal form, which of the
following is not necessary
a) Elimination of null production b) Elimination of unit production
c) Converting given grammar in Chomsky normal form d)None of these

5. Which of the following statements is the most correct answer? [ ]


a) A language is ambiguous if every sentence has two or more parse trees
b) A language is unambiguous if every sentence has a unique left-most derivation
c) A context-free grammar is ambiguous if the right-hand side of one of its
production rules starts with the non-terminal that appears on the left-hand side.
d) All three statements above are valid.

6. The language L={0ᵐ1ᵐ0ᵐ| m ≥ 1+ is a [ ]


a) Regular language b) Context free language
c) Both (a) and (b) d) None of these

7. PDA is more powerful than [ ]


a) Turing machine b) Finite automata
c) Both (a) and (b) d) None of these

8. Which operation can be applied on stack? [ ]


a) PUSH b) POP
c) Both (a) and (b) d) None of these

DEPARTMENT OF INFORMATION TECHNOLOGY Page 16


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

9. PDA can be represented with the help of [ ]


a) Instantaneous description b) Transition diagram
c) Transition table d) All of these

10. A push down automata is different than finite automata by [ ]


a) Its memory (stack) b) Number of states
c) Both (a) and (b) d) None of these

11. The push down automata indicate the acceptance of input string in terms of
a) Finial state b) Empty store
c) Both (a) and (b) d) None of these

12. The instantaneous description is PDA shows [ ]


a) Present state b) Stack symbol
c) String to be processed d) All of these

13. A PDA chooses the next move based on [ ]


a) Current state b) Next input symbol
c) Both (a) and (b) d) None of these

14. The symbol Z0 in formal definition of PDA is used for [ ]


a) Stack symbol b) Input symbol
c) Both (a) and (b) d) None of these

15. Context free grammar is not closed under [ ]


a) product b) union
c) complementation d) Kleen star

16. A context free grammar G is in Chomsky normal form if every production is of the
form
a) A → BC or A → A b) A → BC or A → a
c) A → BCa or B → b d) None of these [
]

17. The context free grammar S → A111|S1, A → A0 | 00 is equivalent to [ ]


a) *0ⁿ1ᵐ | n=2, m=3} b) *0ⁿ1ᵐ | n=1, m=5}
c) *0ⁿ1ᵐ | n should be greater than two and m should be greater than four}
d) None of these

18. The context free grammar S → SS | 0S1 | 1S0 | ɛ generates [ ]


a) Equal number of 0’s and 1’s b) Unequal number of 0’s and 1’s
c) Any number of 0’s followed by any number of 1’s d) None of these
19. Which of the following CFG's can't be simulated by an FSM ? [ ]

DEPARTMENT OF INFORMATION TECHNOLOGY Page 17


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

a) s ---> sa | a b) s ---> abX , X --> cY, Y --> a | axY


c) s ---> a sb | ab d) none of these

20. The set {anbn | n = 1, 2, 3 ...} can be generated by the CFG [ ]


a) S →ab | aSb b) S →aaSbb + abS
c) S→ab | aSb | E d) S →aaSbb | ab | aabb

21. Consider the grammar : [ ]


S —> ABCc | Abc, BA —> AB, Bb —> bb, Ab —> ab, Aa —> aa
Which of the following sentences can be derived by this grammar
a) abc b) aab c) abcc d) abbb
22. Any string of terminals that can be generated by the following CFG is [ ]
S→ XY , X→aX | bX | a, Y→Ya | Yb | a
a) has atleast one 'b' b) should end in a 'a'
c) has no consecutive a's or b's d) has atleast two a's
23. If L1 and L2 are context free language and R a regular set, then which one of the languages
below is not necessarily a context free language? [ ]
a) L1 L2 b) L1 ∩ L2
c) L1 ∩ R d) L1 ∪ L2
24. In a context-free grammar [ ]
a) ε can't be the right hand side of any production
b) terminal symbols can't be present in the left hand side of any production
c) number of grammar symbols in the left hand side is not greater than the number of
grammar symbols in the right hand side
d) all of these
25. A grammar that produces more than one parse tree for some sentence is called_______________
26. Following context free grammar
S —> aB | bA, A —>b | aS | bAA, B —> b | bS | aBB
generates strings of terminals that have [ ]
a) equal number of a's and b's
b) o dd number of a's and odd number b's
c) even number of a's and even number of b's
d) odd number of a's and even number of a's

27. S –> aSa| bSb| a| b ;The language generated by the above grammar over the alphabet {a,b}
is the set of [ ]
a) All palindromes. b) All odd length palindromes.
c) Strings that begin and end with the same symbol d) All even length palindromes.

Section B: Descriptive questions


1. Define Derivation tree.
2. Define Left most derivation and Right most derivation
3. Define Useless Symbols with an example
4. Define null Productions with an example

DEPARTMENT OF INFORMATION TECHNOLOGY Page 18


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

5. Define Unit productions with an example


6. Explain Pushdown Automata
7. Explain Instantaneous description of PDA
8. Explain Left Recursion with an example. Explain the Procedure for elimination of
left recursion.
9. Explain Left Factoring with an example. Explain the procedure to eliminate left
factoring.
10. Define Yield of the tree.
11. Define ambiguous grammar with an example
12. Explain the acceptance of PDA by final state and empty stack
13. Explain DPDA and DCFL
14. List the enumeration properties of Context Free Languages
15. Explain the pumping lemma for CFL
16. Construct the CFG for the Language L={anbn/n>=1}
17. Construct the CFG for the language L={anb2n/n>=0}
18. Find the Language generated by the following grammar
S→SS|aa
19. Find the langugage generated by the following grammar
S→aSa|S→bSb|S→c
20. Construct CFG to generates palindrome for binary numbers.
21. Construct CFG to generate balanced parenthesis
22. Construct an equivalent grammar which is reduced
S→AB,A→a,B→C|b,C→D,D→E,E→a
23. Reduce the following grammars to Chomsky normal forms
a) S→ASA|bA,A→B|S,B→c
b) S→1A|0B, A→1AA|0S|0, B→0BB|1S|1
c) S→a|b|cSS
d) S→abSb|a|aAb, A→bS | aAAb
24. Reduce the following grammars to Greibach Normal Form
a) S→ABb|a,A→aaA,B→bAb
b) S→SS, S→0S1| 01
c) S→AB, A→BSB, A→BB, B→aAb, B→a, A→b
d) S→A0, A→0B, B→A0, B→1
25. Construct PDA for language L={anb2n|n>=1}
26. Construct PDA accepting the set of all strings over {a,b} with equal number of a's
and b's
27. Construct a PDA accepting L={anbman|n>=1}
28. Construct a PDA accepting L={WCWR|w∈ (a,b)*+
29. Show that L={anbncn/n>=1} is not context free

Section C: GATE questions

DEPARTMENT OF INFORMATION TECHNOLOGY Page 19


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

1. Context-free languages are GATE 1992


a) closed under union b) closed under complementation
c) closed under intersection d) closed under Kleene closure
2. Let G be a context-free grammar where G = ({S, A, B, C}, {a, b, d}, P,S) with the
productions in P given below.
GATE 1996
S→ABAC, A→aA|ε, B→bB|ε, C→d
(ε denoted the null string). Transform the grammar G to an equivalent context free
grammar G that has no ε productions and no unit productions. ( A unit production is
of the form x y, and y are non terminals).
3. Which of the following language over {a,b,c} is accepted by a deterministic
pushdown automata? GATE 1997
a) {WCW |W∈(a,b)*+
R b) {WW |W∈(a,b,c)*+
R

c) {anbncn/n>=1} d) {W| W is a palindrome over {a,b,c}}


4. Let M=({q0,q1},{0,1},{z0,X+,δ,q0,z0,φ) be a Pushdown automation where δ is
given by δ (q0,1, z0) = {(q0,xz0)} , δ (q0, ε, zo) = {(q0, ε)+ , δ (q0,1, X) = {(qo , xx)}, δ (q 1 , 1, X)=
{(q 1, ε)}, δ (q0,0, X) = {(q 1 , X )}, δ (q0,0, zo) = {(q o, z o)
What is the language accepted by this PDA by empty store?
Describe informally the working of the PDA. GATE 1998

5. Let L denotes the language generated by the grammar S→0S0/00. GATE 1999
Which of the following is true?
a) L = 0+ b) L is regular but not 0+
c) L is context free but not regular d) L is not context free
6. consider the following two statements: GATE 2001
S1: {0 | n ≥1 }is a regular language
2n

S2: {0n 1m 0m+n | m ≥ 1 and n≥1 } is a regular language


Which of the following statements is correct?
a) Only S1 is correct b) Only S2 is correct
c) Both S1 and S2 are correct d) None of S1 and S2 is correct
7. Which of the following statements s true? GATE 2001
a) If a language is context free it can always be accepted by a deterministic
push-down automaton
b) The union of two context free languages is context free
c) The intersection of two context free languages is context free
d) The complement of a context free language is context free
8. L1={0n+m1n0m | m,n≥1} , L2={0n+m1n+m0n | m,n≥1 }, L3={0n+m1n+m0n+m | m,n≥1 }
Which of these languages are NOT context free? GATE 2006
a) L1 only b) L3 only
c) L1and L2 d) L2 L3
9. Consider the following statements about the context free grammar GATE 2006
G={S→SS,S→ab,S→ba,S→ ε}
I. G is ambiguous
II. G produces all strings with equal number of a’s and b’s

DEPARTMENT OF INFORMATION TECHNOLOGY Page 20


FORMAL LANGUAGES & AUTOMATA THEORY UNIT V

III. G can be accepted by a deterministic PDA.


Which combination below expresses all the true statements about G?
(A) I only
(B) I and III only
(C) II and III only
(D) I, II and III
10. Consider the CFG with {S,A,B} as the non-terminal alphabet, {a,b}as the terminal
alphabet, S as the start symbol and the following set of production rules:
S→aB S→bA
B→b A→a
B→bS A→aS
B→aBB S→bAA
Which of the following strings is generated by the grammar? GATE 2007
a) aaaabb b) aabbbb c) aabbab d) abbbba

DEPARTMENT OF INFORMATION TECHNOLOGY Page 21

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy