solution-sample-final

solution-sample-final - CSE 460 Solutions to Sample Final...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSE 460 - Solutions to Sample Final Exam Fall Semester, 2007 Name The type A points on this exam sum to 13. The type B points on this exam sum to 26. The type C points on this exam sum to 17. The type D points on this exam sum to 22. There are 3 extra credit points that can be applied to any category. 1. Consider the following grammar G 1 defined in abbreviated format. E → E + E | E * E | 4 | 5 | 6 | 7 Given the following leftmost derivation of the string 4+5 * 6+7, answer the following questions. E ⇒ E + E ⇒ E * E + E ⇒ E + E * E + E ⇒ 4+ E * E + E ⇒ 4+5 * E + E ⇒ 4+5 * 6+ E ⇒ 4 + 5 * 6 + 7. (a) Draw the corresponding parse tree. [2, A] E /|\ / | \ E + E /|\ | / | \ | E * E 7 /|\ | / | \ | E + E 6 | | | | 4 5 (b) Draw the corresponding rightmost derivation. [2, A] E ⇒ E + E ⇒ E +7 ⇒ E * E +7 ⇒ E * 6+7 ⇒ E + E * 6+7 ⇒ E +5 * 6+7 ⇒ 4+5 * 6+7. (c) Give the numerical value of 4 + 5 * 6 + 7 implied by the above parse tree. [1,A] 9 * 6 + 7 = 61 (d) Give an alternative leftmost derivation for 4 + 5 * 6 + 7. [2,A] E ⇒ E + E ⇒ 4 + E ⇒ 4 + E * E ⇒ 4 + 5 * E ⇒ 4 + 5 * E + E ⇒ 4 + 5 * 6 + E ⇒ 4 + 5 * 6 + 7. (e) Correct the following incorrect definition of an ambiguous CFG G . [2,A] A CFG G is ambiguous if G has two or more distinct derivations for some string 1 x ∈ L ( G ). A CFG G is ambiguous if G has two or more distinct leftmost or rightmost derivations for some string x ∈ L ( G ). 2. Given the following two grammars G 1 and G 2 , apply the constructions we have seen in class to generate a new grammar G 3 such that L ( G 3 ) = ( L ( G 1 ) L ( G 2 )) * . Specify G 3 completely (not in abbreviated format). [4, B] G 1 G 2 V 1 = { S,T } V 2 = { S,T } Σ = { a,b } Σ = { a,b } Start variable S 1 is S Start variable S 2 is T P 1 = S → aSa | aT, T → bbST | b P 2 = S → bT | aS, T → ST | abab Grammar G 3 • V 3 = ( S 1 ,T 1 ,S,T,U,V ) • Σ = { a,b } • Start variable S 3 is V • P 3 = V → UV | λ U → S 1 T S 1 → aS 1 a | aT 1 T 1 → bbS 1 T 1 | b S → bT | aS T → ST | abab 3. Suppose we apply the construction covered in class to construct an FSA M 2 from an NFA M 1 with 10 total states and 3 accepting states such that L ( M 2 ) = L ( M 1 ). (a) How many total states does M 2 have? [1, B] 2 10 (b) How many accepting states does M 2 have? [1, B] 2 9 + 2 8 + 2 7 2 4. Chomsky Normal Form (a) Identify all the nullable variables in the following grammar G 1 with start variable S . [1,B] S → ABCD | a A → BCD | BC | b B → CC C → a | b | λ D → aa | DD Nullable variables: A , B , and C (b) Apply the algorithms from class to produce a grammar G 2 such that L ( G 2 ) = L ( G 1 ) where G 2 has no λ-productions. [1,B] S → ABCD | ABD | ACD | BCD | AD | BD | CD | D | a A → BCD | BD | CD | D | BC | B | C | b B → CC | C C → a | b D → aa | DD (c) Apply the algorithms from class to produce a grammar G 3 by eliminating the unit productions from the grammar G 2 . [1,B] S → ABCD | ABD | ACD...
View Full Document

This note was uploaded on 07/25/2008 for the course CSE 460 taught by Professor Torng during the Fall '07 term at Michigan State University.

Page1 / 8

solution-sample-final - CSE 460 Solutions to Sample Final...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online