Ambiguity

If an English sentence has more than one meaning, it is said to be ambiguous. Often such sentences can be parsed in more than one way. The sentence,

can be interpreted with time as a noun, flies as a verb and like an arrow as an adverbial phrase. This interpretation is a comment on the fast passage of time. However, if time is interpreted as an adjective, flies as a noun, like as a verb, and arrow as a direct object noun, the sentence becomes a comment on the love life of some species called a time fly. There are other interpretations of this sentence. (see Exercise 4 )

Similarly, meaning is assigned to programming language constructs based on their syntax. We prefer, therefore that programming language grammars describe programs unambiguously.

A sentence is ambiguous if there is more than one distinct derivation. If a sentence is ambiguous, then the parse tree is not unique; we can create more than one parse tree for the same sentence.

A grammar is ambiguous if it can generate even one ambiguous sentence.

Ambiguous grammar for Expressions

Ambiguous grammar for IF-THEN-ELSE

Send questions and comments to: Karen Lemone