hw6-solutions

# hw6-solutions - 7 The set of all strings not in{a n b n c n...

This preview shows pages 1–2. Sign up to view the full content.

CS 381 Assignment 6 Solutions Please note that there are many possible solutions for each of the CFG’s. 1. {xx R ww R | x {a,b}*,w {a,b}*} S -> EE E -> ε | aEa | bEb 2. {a n b m c n+m | n,m 0} S -> aSc | T T -> bTc | 3. {a i b j | i = j or i = 2j} S -> T | U T -> aTb | U -> aaUb | 4. 01{0 n 10 n+1 1}* S -> 01T T -> | TT | U01 U -> 0U0 | 1 5. {a i b j c k d l | i = k or j = l} S -> TD | AU T -> B | aTc U -> C | bUd A -> aA | B -> bB | C -> cC | D -> dD | 6. The set of all strings not in {wcw R | w {a,b}*} The idea here is to generate an error in the string wcw R. S -> aSa | bSb | aEb | aEc | bEa | bEc | cEa | cEb E -> aE | bE | cE | The productions from S -> aEb | aEc | bEa | bEc | cEa | cEb create the desired error in the string, with either unmatching letters on each side (aEb, bEa) or unequal number of letters on each side of c (aEc, cEa, bEc, cEb).

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 7. The set of all strings not in {a n b n c n | n ≥ 1} Generate an error by having too many of one letter. S -> TC | UC | AV T -> aTb | aT | a ( generates excess a’s) U -> aUb | Ub | b ( generates excess b’s) V -> bVc | Vc | c ( generates excess c’s) A -> aA | ε C -> cC | We also need to Union this with all strings not of the form a*b*c*. 8. The set of all strings not in {01001000100001…10 n 1 | n ≥ 1} The idea here is to generate 0 i 10 j as a substring, where i+1 != j. There are two cases, either i >= j, or j >= i+2. S -> E1 Σ * | Σ *1E1 Σ * E -> T | U (E generates the error) T -> 0T0 | 0T | 1 (generates i >= j, too many 0’s on the left side) U -> V00 (generates j >= i+2, too many 0’s on the right side) V -> 0V0 | V0 | 1...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

hw6-solutions - 7 The set of all strings not in{a n b n c n...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online