Difference Between Ambiguous and Unambiguous Grammar-
Before you go through this article, make sure that you have gone through the previous article on Ambiguous Grammar.
Some of the important differences between ambiguous grammar and unambiguous grammar are-
|A grammar is said to be ambiguous if for at least one string generated by it, it produces more than one-
|A grammar is said to be unambiguous if for all the strings generated by it, it produces exactly one-
|For ambiguous grammar, leftmost derivation and rightmost derivation represents different parse trees.
|For unambiguous grammar, leftmost derivation and rightmost derivation represents the same parse tree.
|Ambiguous grammar contains less number of non-terminals.
|Unambiguous grammar contains more number of non-terminals.
|For ambiguous grammar, length of parse tree is less.
|For unambiguous grammar, length of parse tree is large.
|Ambiguous grammar is faster than unambiguous grammar in the derivation of a tree.
(Reason is above 2 points)
|Unambiguous grammar is slower than ambiguous grammar in the derivation of a tree.
E → E + E / E x E / id
E → E + T / T
T → T x F / F
F → id
Next Article- Algorithm To Check Grammar Ambiguity
Get more notes and other study material of Theory of Automata and Computation.
Watch video lectures by visiting our YouTube channel LearnVidFun.