0% found this document useful (0 votes)
35 views5 pages

FALLSEM2020-21 CSE2002 TH VL2020210106983 Reference Material I 21-Aug-2020 Ambiguity

- The document discusses the difference between inherently ambiguous languages and languages that are not inherently ambiguous. - An inherently ambiguous language is one where all grammars that generate the language are ambiguous, while a language that is not inherently ambiguous has at least one unambiguous grammar. - The language L = an, n>=0 is given as an example of a language that is not inherently ambiguous, as it has both ambiguous and unambiguous grammars that generate it. - The language L = { anbncm } ∪ { anbmcm } is an example of an inherently ambiguous language, as the only grammar that generates it is ambiguous.

Uploaded by

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

FALLSEM2020-21 CSE2002 TH VL2020210106983 Reference Material I 21-Aug-2020 Ambiguity

- The document discusses the difference between inherently ambiguous languages and languages that are not inherently ambiguous. - An inherently ambiguous language is one where all grammars that generate the language are ambiguous, while a language that is not inherently ambiguous has at least one unambiguous grammar. - The language L = an, n>=0 is given as an example of a language that is not inherently ambiguous, as it has both ambiguous and unambiguous grammars that generate it. - The language L = { anbncm } ∪ { anbmcm } is an example of an inherently ambiguous language, as the only grammar that generates it is ambiguous.

Uploaded by

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

•The term “inherently ambiguous language” is used instead of “ambiguous

language”.
•This is because all the grammars which generate that language are
ambiguous.

Important Points-
 
If a grammar is ambiguous, it does not imply that its
language will be ambiguous too.
If a grammar is ambiguous, its language may be
unambiguous.
If a grammar is ambiguous, its language will be
unambiguous when there exists at least one
unambiguous grammar which generates that
language.
Example Of Not An Inherently Ambiguous
Language-
Consider the following language-
L = an , n>=0
 
•This language consists of strings having any number of
a’s.
•Few grammars which generate this language are-
 
Grammar-01:
 
S → aS / ∈
(Unambiguous Grammar)
 
Grammar-02:
 
S → aS / a / ∈
(Ambiguous Grammar)
• Grammar-03:
 
• S → aS / Sa / ∈
• (Ambiguous Grammar)
 
• Grammar-04:
•  
• S → aS / a / Sa / ∈
• (Ambiguous Grammar)
 
• All the above grammars generate the same language L = an ,
n>=0.
• Grammar-01 is unambiguous.
• Since there exists at least one unambiguous grammar which
generates language L.
• Therefore, L is not an inherently ambiguous language.
Example Of An Inherently Ambiguous Language-
 
Consider the following language-
L = { anbncm } ∪ { anbmcm }
 
There exists only one grammar which generates this language L.
The grammar is-
 
S → S1 / S2
S1 → S1C / A
A → aAb / ∈
S2 → aS2 / B
B → bBc / ∈
 
• This grammar is ambiguous in nature.
• There exists no language that generates this language
L and is unambiguous.
• Therefore, L is an inherently ambiguous language.
Ambiguous Grammar Unambiguous Grammar

A grammar is said to be ambiguous if for at least A grammar is said to be unambiguous if for all the
one string generated by it, it produces more than
strings generated by it, it produces exactly one-
one-
•parse tree
•parse tree
•or derivation tree
•or derivation tree •or syntax tree
•or syntax tree
•or leftmost derivation
•or leftmost derivation
•or rightmost derivation •or rightmost derivation

For ambiguous grammar, leftmost derivation and For unambiguous grammar, leftmost derivation
rightmost derivation represents different parse and rightmost derivation represents the same
trees. parse tree.

Ambiguous grammar contains less number of Unambiguous grammar contains more number of
non-terminals. non-terminals.

For ambiguous grammar, length of parse tree is For unambiguous grammar, length of parse tree
less. is large.

Ambiguous grammar is faster than unambiguous


grammar in the derivation of a tree. Unambiguous grammar is slower than ambiguous
grammar in the derivation of a tree.
(Reason is above 2 points)

Example- Example-
  E → E + T / T
E → E + E / E x E / id T → T x F / F
(Ambiguous Grammar) F → id
  (Unambiguous Grammar)

You might also like