📜  歧义语法和歧义语法之间的区别

📅  最后修改于: 2021-07-05 07:11:08             🧑  作者: Mango

先决条件–上下文无关文法
1.模棱两可的语法:
如果存在一个以上的派生树或解析树,则无上下文无关的语法称为模糊语法。

例子 –

S -> S + S / S * S / S / a 

2.明确的语法:
如果存在一个且只有一个派生树或解析树,则无上下文无关的语法称为明确语法。

例子 –

X -> AB
A -> Aa / a
B -> b 

歧义语法和歧义语法之间的区别:

S.NO Ambiguous Grammar Unambiguous Grammar
1. In ambiguous grammar, the leftmost and rightmost derivations are not same. In unambiguous grammar, the leftmost and rightmost derivations are same.
2. Amount of non-terminals in ambiguous grammar is less than in unambiguous grammar. Amount of non-terminals in unambiguous grammar is more than in ambiguous grammar.
3. Length of the parse tree in ambiguous grammar is comparatively short. Length of the parse tree in unambiguous grammar is comparatively large.
4. Speed of derivation of a tree in ambiguous grammar is faster than that of unambiguous grammar. Speed of derivation of a tree in unambiguous grammar is slower than that of ambiguous grammar.
5. Ambiguous grammar generates more than one parse tree. Unambiguous grammar generates only one parse tree.
6. Ambiguous grammar contains ambiguity. Unambiguous grammar does not contain any ambiguity.