Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 21

Established as per the Section 2(f) of the UGC Act, 1956

Approved by AICTE, COA and BCI, New Delhi

Lecture 25.2
Ambiguity in Grammars and languages
S c h o o l o f C o m p u t i n g a n d I n f o r m a t i o n Te c h n o l o g y

Chaithra M H

AY:2020-2021
OUTLINE
Recap of Previous Lecture

Topic of the Lecture

Objective and Outcome of Lecture

Lecture Discussion

• Problems on Ambiguity in Grammars and languages


Ambiguity in Grammars and languages
Recap of Previous Lecture
RECAP OF PREVIOUS LECTURE

Problems on Ambiguity in Grammars and languages


Ambiguity in Grammars and languages
Topic for the lecture
• Problems on
Grammar
Ambiguity in Ambiguous
Grammars and
languages
TOPIC OF THE LECTURE
Ambiguity in Grammars and languages
Objective and Outcome of Lecture
• Identify
and
construct
Ambiguit
y in
Gramma Outcome
rs and Lecture
language
s by
applying
• LMD or
Illustrat
RMD
e the
techniqu
constru
es.
ction of Objective
Ambigui Lecture
ty in
Gramm
ars and
languag
es.
OBJECTIVE AND OUTCOME OF LECTURE
Ambiguity in Grammars and languages
Problems
Example Boolean Algebra

Consider the CFG G=(V,,P,S) with


V = {S,Z}
 = {0,1,(,),,,}
P: S  0 | 1 | (S) | (S)(S) | (S)(S)

Some elements of L(G):


0
(((0))(1))
(1)((0)(0))
Note: Parentheses prevent “100” confusion.
EXAMPLE-1
Parse Trees
• Consider the parse tree of (0)((0)(1))
S  0 | 1 | (S) | (S)(S) | (S)(S)

( S )  ( S )

0 S
( )  ( S )

0 1
Ambiguity

A grammar is ambiguous if some strings are derived ambiguously.

A string is derived ambiguously if it has more than one leftmost


derivations.
Typical example: rule S  0 | 1 | S+S | SS

S  S+S  SS+S  0S+S  01+S  01+1


versus
S  SS  0S  0S+S  01+S  01+1
Ambiguity and Parse Trees

The ambiguity of 01+1 is shown by the two different parse trees:


Parse tree-1 Parse tree-2 S
S

S  S
S + S
0
S  S 1 S + S

0 1 1
1
More on Ambiguity

The two different derivations:


S  S+S  0+S  0+1
and
S  S+S  S+1  0+1
do not constitute an ambiguous string 0+1
(they will have the same parse tree)

Languages that can only be generated by ambiguous grammars are


“inherently ambiguous”
Problems on
Ambiguity in
Ambiguity in
Grammars
Grammars
and languages
and languages
SUMMARY OF THE LECTURE
DISCUSSION
5 MINUTES
QUIZ TIME
10 MINUTES

“All of you have to give quiz where there


will be 8 questions covering part1 and
part 2 of lecture. It is compulsory as it is
used for assessment and attendance”
QUIZ
Questions from Lecture 25.1 & 25.2

1. Grammar that produce more than one Parse tree for same sentence is:

A) Concatenation Intersection B) Ambiguous grammar

2. Grammars that can be translated to DFAs:

A) Left linear B) Right linear


QUIZ
Questions from Lecture 25.1 & 25.2

3. 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}

4. The context free grammar S → SS | 0S1 | 1S0 | ɛ generates

A) Equal number of 0’s and 1’s B) Number of 0’s followed by any


number of 1’s
QUIZ
Questions from Lecture 25.1 & 25.2

5. S → SS S → λ S → aSb S → bSa which type of grammar is it?

A) Linear grammar B) Non-linear grammar


THANK YOU

You might also like