exam2-2005

exam2-2005 - COP5621 Exam 2 - Spring 2005 (Please print)...

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: COP5621 Exam 2 - Spring 2005 (Please print) Name: Put the answers on these sheets. Use additional sheets when necessary. Show how you derived your answer when applicable (this is required for full cred it and helpful for partial credit). You can collect 100 points in total for this exam. A bonus question for an additional 15 points is included. If the total number of points for this exam exceed 100, the excess points are carried over to the next exams. 1. Match the terms below with the given sentences so as to best complete each sentence. Use no term more than once. Some terms will go unused. (10 points) (1) (2) (3) (4) (5) (6) (a) In a step. context-free terminal LL(1) SLR lexeme nonterminal (7) (8) (9) (10) (11) (12) leftmost rightmost LR(1) LALR(1) string context-sensitive derivation, the rightmost nonterminal in a sentential form is replaced in each (b) Recursive-descent parsing can be used for grammars (list all that apply). (c) A shift-reduce conflict may arise in constructing a parsing table (list all that apply). (d) In a context-free grammar, each production has a single (e) The yield of a parse tree is a sequence of 2. Name the four error recovery strategies. (10 points) 1 s. on the left-hand side. 3. Show that the following grammar is ambiguous by constructing two distinct leftmost derivations for the string abab. Also show the two distinct parse trees. (15 points) S → aSbS|bSaS|ε 4. Consider the following grammar: start label stmt expr → → | → | → | label stmt num ε id := expr goto num id num For each production A → α, determine FIRST(α) and FOLLOW(A). (15 points) 2 5. Disprove that the following grammar is LL(1). (15 points). S A B → → → Aa b|Bbc c|ε 6. Eliminate left recursion from the following grammar. Use the algorithm described in the book and illustrated in class. (15 points) A B → → 3 BA|a AB|b 7. Given below is the collection of LR(0) items for the grammar 1. 2. 3. 4. L → L || L L → L && L L → !L L→b Construct an SLR parsing table. There are shift-reduce conflicts. You must resolve the shiftreduce conflicts by choosing either a shift or reduce depending on the following assumptions: • The operators ||, &&, ! are listed in increasing order of precedence, • The operators || and && are left associative, i.e. b&&b&&b = (b&&b)&&b. Indicate your choice for each conflict by circling the shift or reduce. (20 points) I0 : L￿ → · L goto(L)=I1 L → · L || L goto(L)=I1 L → · L && L goto(L)=I1 L → ·!L goto(!)=I2 L → ·b goto(b)=I3 ￿ → L· I1 : L L → L · || L goto(||)=I4 L → L · && L goto(&&)=I5 I2 : L → ! · L goto(L)=I6 L → · L || L goto(L)=I6 L → · L && L goto(L)=I6 L → ·!L goto(!)=I2 L → ·b goto(b)=I3 I3 : L → b · I4 : L → L || · L goto(L)=I7 L → · L || L goto(L)=I7 L → · L && L goto(L)=I7 L → ·!L goto(!)=I2 L → ·b goto(b)=I3 I5 : L → L && · L goto(L)=I8 L → · L || L goto(L)=I8 L → · L && L goto(L)=I8 L → ·!L goto(!)=I2 L → ·b goto(b)=I3 I6 : L → ! L · L → L · || L goto(||)=I4 L → L · && L goto(&&)=I5 I7 : L → L || L · L → L · || L goto(||)=I4 L → L · && L goto(&&)=I5 I8 : L → L && L · L → L · || L goto(||)=I4 L → L · && L goto(&&)=I5 4 8. (bonus question). Given the following grammar, construct the LR(1) collection of sets of items with goto transitions. (15 points) S X X Y Y → → → → → To get started, the first set of items I0 is I0 : S￿ S X X Y Y → → → → → → ·S ,$ ·XY ,$ · Y b , $/c · b , $/c ·c ,b · ,b goto(S )=I1 goto(X )=I2 goto(Y )=I3 goto(b)=I4 goto(c)=I5 5 XY Yb b c ￿ ...
View Full Document

This note was uploaded on 02/01/2012 for the course COP 5621 taught by Professor Vanengelen during the Spring '11 term at FSU.

Ask a homework question - tutors are online