edited by
3,933 views
3 votes
3 votes

An ambiguous grammar is one that produces

  1. more than one left most derivation for the same sentence.
  2. more than one right most derivation for the same sentence.
  3. more than one leftmost derivation for the different sentence.
    1. i and ii
    2. i or ii
    3. ii and iii
    4. ii or iii
edited by

2 Answers

Best answer
4 votes
4 votes

An ambiguous grammar is one for which there is more than one parse tree for a single sentence. Since each parse tree corresponds to exactly one leftmost derivation, a grammar is ambiguous if and only if it permits more than one leftmost derivation of a given sentence. Similarly, a grammar is ambiguous if and only if it permits more than one rightmost of a given sentence.

Example:

    E → E + E | E * E | ( E ) | id
  

is ambiguous because we have two parse trees for 
id + id * id 
So there must me at least two leftmost derivations. Here they are

          

 E ⇒ E + E          E ⇒ E * E
      ⇒ id + E           ⇒ E + E * E
      ⇒ id + E * E       ⇒ id + E * E
      ⇒ id + id * E      ⇒ id + id * E
      ⇒ id + id * id     ⇒ id + id * E

Hence,Option(B)i or ii is the correct choice.

edited by
0 votes
0 votes
Ambiguos grammar have more that one RMD for same given string along with same number of LMD for given string so such grammar are known as amgiguos grammar.

Not only this deffinition but a grammar is said to be ambiguos grammar if it has also more than one derivation tree for a given grammar.

Related questions

2 votes
2 votes
2 answers
1
Shashank Chandekar asked Nov 3, 2016
4,240 views
Consider the following context-free grammarS → SS + | SS*| a for the string aa + a*. Is the grammar ambiguous ?
0 votes
0 votes
0 answers
3
7 votes
7 votes
1 answer
4
Aditya asked Aug 6, 2015
8,818 views