0% found this document useful (0 votes)
12 views

A Language L Is Said To Be Context-Free If There Is A CFG G That Accepts L

1. The document defines context-free languages and grammars. It provides examples of context-free languages and their grammars. It also discusses minimizing deterministic finite automata. 2. It asks to design pushdown automata for specific languages and show their moves for sample strings. It also asks to obtain unambiguous grammars and show derivations. 3. It asks to design a pushdown automaton for a specific language and show its instantaneous descriptions. It also asks to determine if a given grammar is ambiguous or not by showing two distinct derivations for a string.

Uploaded by

lokotwiststudio2
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)
12 views

A Language L Is Said To Be Context-Free If There Is A CFG G That Accepts L

1. The document defines context-free languages and grammars. It provides examples of context-free languages and their grammars. It also discusses minimizing deterministic finite automata. 2. It asks to design pushdown automata for specific languages and show their moves for sample strings. It also asks to obtain unambiguous grammars and show derivations. 3. It asks to design a pushdown automaton for a specific language and show its instantaneous descriptions. It also asks to determine if a given grammar is ambiguous or not by showing two distinct derivations for a string.

Uploaded by

lokotwiststudio2
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/ 7

Unit – I Marks

1. Define context-free language. Show that the following languages on


a)
∑ = {𝑎, 𝑏} are context-free .

A language L is said to be context-free if there is a CFG G that


accepts L.
i. Set of all strings with at least one ‘a’
S→ bS | aA
A→ aA | bA | ε

OR
S→ AaA
A→ aA | bA | ε

ii. L= ai bj | i≠ j }
S→ aSb | A |B
A→ aA | a
B→ bB | b 1+2+2
b) Minimize the following DFA.

3+2
2. a) Minimize the following DFA.

0 1
(q0,q3) (q1,q5) (q2,q5)
(q0,q4) (q1,q5) (q2,q5)
(q1,q2) (q3,q3) (q4,q3)
(q1,q5) (q3,q5) (q4,q5)
(q2,q5) (q4,q5) (q3,q5)
(q3,q4) (q5,q5) (q5,q5)

0 1
(q0,q3) (q1,q5) (q2,q5) 3+2
(q0,q4) (q1,q5) (q2,q5)
(q1,q2) (q3,q3) (q4,q3)
(q3,q4) (q5,q5) (q5,q5)

0 1
(q1,q2) (q3,q3) (q4,q3)
(q3,q4) (q5,q5) (q5,q5)

Indistinguishable states are : (q1,q2) , (q3,q4)


Distinguishable states: q0, q5
Minimized DFA is
b) Define context-free grammar (CFG). Find CFGs for the following
languages.
A grammar with every production of the form A→x where x ϵ (V U T)*
and A ϵ V is called CFG.

i) 𝐿 = {𝑤: |𝑤|𝑚𝑜𝑑3 ≠ |𝑤|𝑚𝑜𝑑2}on ∑ = {𝑎}

S -> aa | aaa | aaaa | aaaaa | aaaaaaS


OR

S→aA
A→aB
B→aC | ⋵
C→aD | ⋵
D→aE | ⋵
E →aS | ⋵

ii) 𝐿 = {𝑎i𝑏j𝑐k : 𝑖 + 2𝑗 = 𝑘, 𝑖, 𝑗, 𝑘 ≥ 0} on ∑ = {𝑎, 𝑏, 𝑐}


S-> aSc | B
B -> bBcc | ⋵ 1 +2 + 2
Unit – II
3. a) Design an npda for 𝐿 = {𝑎n𝑏m𝑐k : 𝑘 = 𝑛 + 𝑚, 𝑛, 𝑚, 𝑘 ≥ 0} on ∑=
{𝑎, 𝑏, 𝑐}}. Show the moves made by npda for 𝑤 = 𝑎𝑎𝑏𝑐𝑐𝑐.

1+3 + 2
Or equivalent transition diagram can be written.

b) Obtain an unambiguous grammar for the following expression


grammar.
E→ E+E | E-E | E*E | E/E | (E) | a | b | c

where + and – have higher priority than * and / and are right
associative. Show a derivation of 𝑎 + (𝑏 ∗ 𝑐) using the resulting
grammar.

Required unambiguous grammar.


E → E*T | E/T | T
T → F+T | F-T |F
F → (E) | a | b |c

Derivation for w = a+(b*c) 2+2


E=> T
=>F+T
=> a+ T
=> a+ F
=> a + (E)
=> a+ (T *E)
=> a+ (F *E )
=> a + (b * E)
=> a+ (b *T )
=> a+ (b * F )
=> a+ (b*c )
4 a) Design an npda for the language 𝐿 = {𝑤𝑤R | 𝑤 ∈ (𝑎, 𝑏)*} . Show the instantaneous
descriptions (IDs) for the string 𝑤 = 𝑎𝑏𝑏𝑎.

1+3+2
Or equivalent transition diagram can be written

(Expected similar IDs for w = abba)


b) Define ambiguous grammar. Determine whether the following grammar is
ambiguous or not. Consider 𝑤 = 𝑎𝑎𝑏𝑎𝑏𝑏.
𝑆 → 𝑎𝑆𝑏𝑆| 𝑏𝑆𝑎𝑆|𝜖
A grammar G is said to be ambiguous if some w in L(G) has atleast two
leftmost (rightmost) derivations ( two distinct derivation trees)

2 Leftmost derivations for w = aababb


1 + 1.5 +
S⇒aSbS S⇒aSbS 1.5
⇒aaSbSbS (𝑆 → 𝑎𝑆𝑏𝑆 ) ⇒aaSbSbS (𝑆 → 𝑎𝑆𝑏𝑆 )
⇒aabSbS (𝑆 → 𝜖) ⇒aabSaSbSbS (𝑆 → 𝑏𝑆𝑎𝑆 )
⇒aabaSbSbS (𝑆 → 𝑎𝑆𝑏𝑆 ) =>aabaSbSbS (𝑆 → 𝜖)
⇒aababSbS (𝑆 → 𝜖) => aababSbS (𝑆 → 𝜖)
=>aababbS (𝑆 → 𝜖) => aababbS (𝑆 → 𝜖)
=> aababb (𝑆 → 𝜖) =>aababb (𝑆 → 𝜖)
Hence the grammar is ambiguous

Or construct two distinct derivation


tress as shown below.

Hence the grammar is ambiguous

BT* Bloom’s Taxonomy, L* Level; CO* Course Outcome; PO* Program Outcome

*****************

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