cs606 collection of old papers

18
When generating a lexical analyzer from a token description, the item sets (states) are constructed by two types of "moves": character moves and ε-moves. ε-moves do not Question No. 1 Marks : 05 Total Marks: 160 Total Questions: 21 **WARNING: Please note that Virtual University takes serious action against unfair means. Anyone found involved in cheating will get an `F` grade in this course. b. On the other hand, if you believe that all of the choices provided for a particular question are wrong then select the one that appears to you as being the least wrong. a. If you believe that two (or more) of the choices are correct for a particular question, choose the best one. 4. Some of the examination consists of multiple-choice questions. Choose only one choice as your answer. b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem. a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding. 3. Do not ask any questions about the contents of this examination from anyone. 2. This examination is closed book, closed notes, closed neighbors. 1. The duration of this examination is 150 Mins. Please read the following instructions carefully before attempting any of the questions: Time Allowed: 150 Minutes Final Term Examination – Spring 2005 CS410 Visual Programming www.vujannat.ning.com

Upload: httpmajidvacom

Post on 04-Apr-2015

268 views

Category:

Documents


9 download

DESCRIPTION

CS606 COLLECTION OF OLD PAPERS

TRANSCRIPT

Page 1: Cs606 Collection of Old Papers

When generating a lexical analyzer from a token description, the item sets (states) are constructed by two types of "moves": character moves and ε-moves. ε-moves do not

Question No. 1 Marks : 05 Total Marks: 160 Total Questions: 21

**WARNING: Please note that Virtual University takes serious action against unfair means. Anyone found involved in cheating will get an `F` grade in this course.

b. On the other hand, if you believe that all of the choices provided for a particular question are wrong then select the one that appears to you as being the least wrong.

a. If you believe that two (or more) of the choices are correct for a particular question, choose the best one.

4. Some of the examination consists of multiple-choice questions. Choose only one choice as your answer.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

3. Do not ask any questions about the contents of this examination from anyone.

2. This examination is closed book, closed notes, closed neighbors. 1. The duration of this examination is 150 Mins.

Please read the following instructions carefully before attempting any of the questions:

Time Allowed: 150 Minutes

Final Term Examination – Spring 2005

CS410 Visual Programming

www.vujannat.ning.com

Page 2: Cs606 Collection of Old Papers

- An inherited attribute can depend on a synthesized attribute.

The dependency graph associated with the attribute evaluation rule of some production rule (N→ α) captures how values flow from one attribute to another, hence, which attribute depends on which others.

Question No. 5 Marks : 05

o False

o True

- an empty production (N → ε) translates to a routine returning true without inspecting any token.

A recursive descent parser consists of a set of (recursive) routines, each routine corresponding closely to a rule in the grammar.

Question No. 4 Marks : 05

o False

o True

can coexist in an LR item set. {A→ P • P,B → Q • Q} The following two items Question No. 3 Marks : 05

(b) Build the LR(1) parse table (Action/Goto) (a) Derive the canonical sets of LR( 1) items

Consider the following augmented grammar

Question No. 2 Marks : 30

o False

o True

consume any input character, but merely expand non-basic items with repetition and composition operators.

Page 3: Cs606 Collection of Old Papers

Consider the productions and semantic rules for the expression grammar Question No. 8 Marks : 25

o False

o True

- For an AST with N attributes, cycles can be detected dynamically by performing (at most) N evaluation traversals.

When dealing with attribute grammars it is important to detect cycles in the evaluation rules to prevent the evaluator to loop endlessly. In the case of dynamic cycle detection, the AST is traversed multiple times until either all attributes have obtained a value, or a maximum number of traversals is reached (in which case a cycle can be reported).

Question No. 7 Marks : 05

o False

o True

- This is a reduce item.

integer → (•[0 - 9])+

Dotted items (T→ α • β) record which part of a token has already been matched. There are two kinds of basic items: shift items and reduce items.

Question No. 6 Marks : 05

o False

o True

Page 4: Cs606 Collection of Old Papers

Consider the following ACTION/GOTO tables: Question No. 12 Marks : 15

o False

o True

The LR(1) parsing technique reduces a handle (the right-hand side of a production N → α) only when the current input token is an element of FOLLOW(N).

Question No. 11 Marks : 05

o False

o True

In a CFG (Context Free Grammar) the set of terminal and non-terminal symbols may overlap.

Question No. 10 Marks : 05

o False

o True

The regular expressions (a |b) + and a+ |b+ describe the same set of strings

Question No. 9 Marks : 05

c) The programming language designer has decided to add the pre-increment operator "++" to the grammar with the production "E →++id". This new operator increments id, and then returns the value (for example after the code, x=5; y=++x; is executed then x is 6 and y is 7). Add the semantic rule that will generate code for this new operator.

b) How many temporary variables are used to implement this?

x:=(a+b)* (c+a)

a) Write the three-address code that would be generated from the semantic rules shown for the program fragment (input string)

Page 5: Cs606 Collection of Old Papers

Question No. 12 Marks : 05

o False

o True

- For generating "optimal" code these three tasks must be considered at once, because they dependent on each other.

3. instruction ordering 2. register allocation 1. instruction selection Code generation consists of three tasks:

Question No. 12 Marks : 05

o False

o True

- Left-factoring takes care of FIRST/FIRST conflicts.

Grammars with LL(1) conflicts can be made LL(1) by applying left-factoring, substitution, and left-recursion removal.

Question No. 12 Marks : 05

o False

o True

- If a node in the graph is connected to N other nodes, then at at least N + 1 registers (colors) are needed.

Register allocation by graph coloring uses a register interference graph. Question No. 12 Marks : 05

Show the contents of the stack and input buffer for the shift-reduce parse of input "a", assuming state 0 is the start state:

Page 6: Cs606 Collection of Old Papers

o True

A top-down parser creates the nodes in the AST (Abstract Syntax Tree) in preorder. Question No. 12 Marks : 05

o False

o True

- The nodes in the graph represent the basic blocks, and the edges capture the ordering dependencies that must be obeyed at execution time.

When generating code at the basic block level, a dependency graph is used instead of an AST.

Question No. 12 Marks : 05

o False

o True

The stack used in a bottom-up parser contains an alternating sequence of states and grammar symbols.

Question No. 12 Marks : 05

o False

o True

The symbol table is used to pass information only between consecutive stages (lexical analysis, semantics analysis, etc.) in the compiler pipeline.

Question No. 12 Marks : 05

o False

o True

A lexical analyzer transforms a stream of characters into a stream of tokens. Question No. 12 Marks : 05

o False

o True

A lexical analyzer generated by lex is essentially a PDA (Push Down Automaton).

Page 7: Cs606 Collection of Old Papers

o False

Page 8: Cs606 Collection of Old Papers

Given the following grammar and input string "bool id , id , id"

Question No. 1 Marks : 20 Total Marks: 55 Total Questions: 4

**WARNING: Please note that Virtual University takes serious action against unfair means. Anyone found involved in cheating will get an `F` grade in this course.

b. On the other hand, if you believe that all of the choices provided for a particular question are wrong then select the one that appears to you as being the least wrong.

a. If you believe that two (or more) of the choices are correct for a particular question, choose the best one.

4. Some of the examination consists of multiple-choice questions. Choose only one choice as your answer.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

3. Do not ask any questions about the contents of this examination from anyone.

2. This examination is closed book, closed notes, closed neighbors. 1. The duration of this examination is 90 Mins.

Please read the following instructions carefully before attempting any of the questions:

Maximum Time Allowed: (1.5 Hour)

Time Allowed: 90 Minutes Mid Term Examination – Spring 2005

CS606 Compiler Construction

www.vujannat.ning.com

Page 9: Cs606 Collection of Old Papers

Note: The states with '*' are final states.

Use the subset construction to create a DFA that is equivalent to the following NFA that uses the alphabet a,b. Show your work.

Question No. 4 Marks : 10

would the table be? (how many entries would it have)

c) If you were going to build a table driven top-down parser for this grammar from (b), how big

b) Rewrite the grammar so that it is suitable for recursive decent parsing FIRST sets

a) Show that the grammar is not LL(1) hint: you should be able to do this by computing some of the

5. | A , S 4. A → S 3. | ( A ) 2. | a 1. S → ( )

Consider the following grammar of lists. Note that there are four different terminals: "(", ")", "a", and ","

Question No. 3 Marks : 15

4. VarTail → (Exp) | ε

3. Var → id VarTail 2. ExpTail → – Exp | ε

1. Exp → – Exp | (Exp) | Var ExpTail Find the First and Follow sets for the following grammars:

Question No. 2 Marks : 10

d. show the parse tree for the above input string on the new grammar c. create a new equivalent grammar that has left recursion removed b. show the parse tree of the input string a. show the leftmost derivation of the input string

3. IdList → IdList , id | id 2. Type → bool | int | float 1. Decl → Type IdList

Page 10: Cs606 Collection of Old Papers
Page 11: Cs606 Collection of Old Papers

www.vujannat.ning.com

X → Y | Z b | a Y S → X S | d S | ε

Consider the context-free grammar Question No. 1 Marks : 25

**WARNING: Please note that Virtual University takes serious action against unfair means. Anyone found involved in cheating will get an `F`

grade in this course.

b. On the other hand, if you believe that all of the choices provided for a particular question are wrong then select the one that appears to you as being the least wrong.

a. If you believe that two (or more) of the choices are correct for a particular question, choose the best one.

4. Some of the examination consists of multiple-choice questions. Choose only one choice as your answer.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

3. Do not ask any questions about the contents of this examination from anyone.

2. This examination is closed book, closed notes, closed neighbors. 1. The duration of this examination is 90 Minutes.

Please read the following instructions carefully before attempting any of the questions:

Time Allowed: 90 Minutes

Mid Term Examination – Spring 2006 CS606 Compiler Construction

Page 12: Cs606 Collection of Old Papers

False True

This grammar is ambiguous.

A → Aa | a S → a | A

Question No. 5 Marks : 2

Insufficient Information False True

NFAs are converted to DFAs because the former cannot be implemented directly. Question No. 4 Marks : 2

Insufficient Information False True

Making a grammar with a FIRST/FIRST conflict LL(1) requires the application of left factoring. Question No. 3 Marks : 2

None of the others False True

A bottom-up parser creates the nodes in the AST in pre-order. Question No. 2 Marks : 2

c) Is the grammar LL(1)? [02 marks]

b) Construct the parsing table for a non-recursive predictive parser for this grammar. [11 marks]

[12 marks] a) Give the FOLLOW and FIRST sets for each non-terminal symbol.

The symbols S, X, Y and Z are non-terminals with S as the start symbol while a, b, c, d, e are terminal symbols.

Z → e Y → c Z

Page 13: Cs606 Collection of Old Papers

E → id == id ;

S → if (E) then S else S S → if (E) then S S → id := id ;

Demonstrate that the following grammar is ambiguous. (HINT: Use parse trees.) Question No. 8 Marks : 10

Note: here ‘*’ shows the final state

5* {} {} {} 4 {} {4} {3} 3 {5} {} {} 2 {2} {3} {4} 1 {2,5} {1,3} {}

Use subset construction to build a DFA equivalent to the NFA below. Show your work. Note: ε is the epsilon symbol.

a b ε

Question No. 7 Marks : 10

None of the others False True

returning true regardless of its (token) value. - an empty production (N→ ε) ‘translates’ to a routine consuming the current input token and

A recursive descent parser consists of a set of (recursive) routines, each routine corresponding closely to a rule in the grammar.

Question No. 6 Marks : 2

None of the others

Page 14: Cs606 Collection of Old Papers

Connecting VU Students

1

FINALTERM EXAMINATION SPRING 2006

CS606 - COMPILER CONSTRUCTION (Session - 1 )

Marks: 75

Time: 120min

StudentID/LoginID: ______________________________

Student Name: ______________________________

Center Name/Code: ______________________________

Exam Date: Wednesday, August 23, 2006

Please read the following instructions carefully before attempting any of the questions:

1. This examination is closed book, closed notes, closed neighbors.

2. Do not ask any questions about the contents of this examination from anyone.

a. If you think that there is something wrong with any of the questions, attempt it to the best of your understanding.

b. If you believe that some essential piece of information is missing, make an appropriate assumption and use it to solve the problem.

3. Some of the examination consists of multiple-choice questions. Choose only one choice as your answer.

a. If you believe that two (or more) of the choices are correct for a particular question, choose the best one.

b. On the other hand, if you believe that all of the choices provided for a particular question are wrong then select the one that appears to you as being the least wrong.

**WARNING: Please note that Virtual University takes serious action against unfair means. Anyone found involved in cheating will get an `F` grade in this course.

For Teacher's use only Question 1 2 3 4 5 6 7 8 Total

Marks

Page 15: Cs606 Collection of Old Papers

Connecting VU Students

2

Question No: 1 ( Marks: 2 ) - Please choose one Circle the choice that is a regular expression for the set of all strings over the alphabet {a} that has an even number of a’s. ►

aa*

(aa)*

aa*a

a(aa)*

Question No: 2 ( Marks: 2 ) - Please choose one A shift reduce parser performs reductions in the reverse order specified by a left-most derivation: ►

False

True

None of these

Question No: 3 ( Marks: 2 ) - Please choose one Consider the context-free grammar with terminal symbols a, b, c, non-terminal symbols A and B where A is the start symbol and productions

A →BAB | a B → b | c | ε

Which of the following strings is not in the language of the grammar? ►

abb

bcacb

bbccab

bcab

bcacba

Page 16: Cs606 Collection of Old Papers

Connecting VU Students

3

Question No: 4 ( Marks: 2 ) - Please choose one Dotted items (T → α • β) record which part of a token has already been matched.

There are two kinds of basic items: shift items and reduce items. integer → (• [0-9]) +

-This is a shift item.

False

True

None of these

Question No: 5 ( Marks: 2 ) - Please choose one A grammar with a FIRST/FIRST conflict can be made LL(1) by only applying left factoring, that is, no substitution and left-recursion removal are needed. ►

False

True

None of these

Question No: 6 ( Marks: 20 ) Consider the grammar

S → a B C d | d C B e B → b B | ε C → c a | a c | ε

(a) What are the terminals, non-terminals, and the start symbol for the grammar? [02 Points] (b) Give the parse tree for the input string abbcad. [02 Points] (c) Compute the First sets and Follow sets for each of the nonterminals in the grammar. [04 Points] (d) Construct an LL(1) parsing table for the grammar. [12 Points] Question No: 7 ( Marks: 30 ) Consider the following grammar over the terminals + , − (the negation operator) and id.

Page 17: Cs606 Collection of Old Papers

Connecting VU Students

4

S → E E → E + E | − E | id

Below is a partial DFA for this grammar.

(a) Complete the above DFA. You need to do the following: [21 points]

• Complete state 0 by performing closure on the item listed. • Fill in all elements of states 1 and 5, and the lookahead items in states 3, 4 and 6. • Fill in the missing transition labels on all edges.

• Write the necessary “reduce by . . . ” labels on states. (b) For each state with a conflict, list the state, the lookahead token, and the type of conflict (i.e. shift-reduce confl ic t , or reduce-reduce confl ict) . [4 points] c) Show that the given grammar is ambiguous (Hint: use the parse tree) [5 points] E → E + T | T T → T + E | id Question No: 8 ( Marks: 15 ) Add semantic rules to the following grammar to compute the attribute rm, whose value is the rightmost terminal in the string we parsed. For example, if the string parsed were zxyxy, S.rm would be y. Note: subscripts in the grammar below are only to distinguish multiple instances of the same

Page 18: Cs606 Collection of Old Papers

Connecting VU Students

5

nonterminal.

S → A {S.rm =

A → A1 x y | B A1 y | C

B → B1 z | x

C → w C1 | y C1 | z