Solution to Homework Problem: Ambiguous Grammar Derivation, Assignments of Computer Science

The solution to a homework problem on deriving left-most and right-most derivations from an ambiguous grammar. It includes the given problem statement, the steps to derive the two distinct derivations, and the explanation of why these derivations indicate ambiguity.

Typology: Assignments

Pre 2010

Uploaded on 08/05/2009

koofers-user-hgj
koofers-user-hgj 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Solution for HW4
Q1.1)
S -> 0 | 1 | 0A0 | 1A1
A -> 0A | 1A | e
Q1.2)
S -> 0A | 1A
A -> 00A | 01A | 10A | 11A | e
Q2)
A -> BAB | B | e
B -> 00 | e
Step1) add start symbol
A0 -> A
A -> BAB | B | e
B -> 00 | e
Step2)
1) remove B->e
A0 -> A
A -> BAB | B | AB | BA | A | e
B -> 00
2) remove A->e
A0 -> A | e
A -> BAB | B | AB | BA | A | BB
B -> 00
Step3)
1) Remove A->B & A->A
A0 -> A | e
A -> BAB | 00 | AB | BA | BB
B -> 00
pf3

Partial preview of the text

Download Solution to Homework Problem: Ambiguous Grammar Derivation and more Assignments Computer Science in PDF only on Docsity!

Solution for HW Q1.1) S -> 0 | 1 | 0A0 | 1A A -> 0A | 1A | e Q1.2) S -> 0A | 1A A -> 00A | 01A | 10A | 11A | e Q2) A -> BAB | B | e B -> 00 | e Step1) add start symbol A0 -> A A -> BAB | B | e B -> 00 | e Step2)

  1. remove B->e A0 -> A A -> BAB | B | AB | BA | A | e B -> 00
  2. remove A->e A0 -> A | e A -> BAB | B | AB | BA | A | BB B -> 00 Step3)
  3. Remove A->B & A->A A0 -> A | e A -> BAB | 00 | AB | BA | BB B -> 00
  1. Remove A0 -> A A0 -> BAB | 00 | AB | BA | BB | e A -> BAB | 00 | AB | BA | BB B -> 00 Step4) Convert into proper form

A0 -> B(B1) | 00 | AB | BA | BB | e A -> B(B1) | 00 | AB | BA | BB B -> 00 B1 -> AB

A0 -> B(B1) | CC | AB | BA | BB | e A -> B(B1) | CC | AB | BA | BB B -> CC B1 -> AB C -> 0 Common mistakes include missing BB, missing e, missing ‘C->0’. Q3. left-most derivation S => aB => aaBB => aaaBBB => aaabBB => aaabbB => aaabbaBB => aaabbabB => aaabbabbS => aaabbabbbA => aaabbabbba Right-most derivation S => aB => aaBB => aaBaBB => aaBaBbS => aaBaBbbA => aaBaBbba => aaBabbba => aaaBBabbba => aaaBbabbba => aaabbabbba (Note that these two derivations are derived from one identical parse tree. You cannot claim that this grammar is ambiguous just because of these two derivations.) Another left-most derivation S => aB => aaBB => aaaBBB => aaabSBB => aaabbABB => aaabbaBB => aaabbabB => aaabbabbS => aaabbabbbA => aaabbabbba