(Department of Computer Science)

WARNING

1. PLAGIARISM OR HIRING OF GHOST WRITER(S) FOR SOLVING THE ASSIGNMENT(S) WILL DEBAR THE STUDENT FROM AWARD OF DEGREE/CERTIFICATE, IF FOUND AT ANY STAGE. 2. SUBMITTING ASSIGNMENT(S) BORROWED OR STOLEN FROM OTHER(S) AS ONE’S OWN WILL BE PENALIZED AS DEFINED IN “AIOU PLAGIARISM POLICY”.

Course: Compiler Construction (3468)Semester: Autumn, 2012

Level: BS (CS)Total Marks: 100

ASSIGNMENT No. 1

Note: All questions carry equal marks.

Q. 1(a)Define Compiler, using a diagram describes the three phases of analysis of source program. (b)Explain all the phases of Compiler.

(c)Consider the following grammar.

S ―> XaYb

X ―> bXc | b

Y ―> dYa | d

Find the first sets for each non-terminal of the given grammar.

Q. 2(a)Explain the error detection and reporting mechanisms. (b)Write the intermediate representation code of the following position: = initial + rate * 60

Q. 3(a)Convert the following NFA into equivalent DFA using subset construction Algorithm. [pic]

Note:Show all necessary steps that are involved in subset construction algorithm. (b) Convert the Following regular expression into NFA using Thompson’s construction. a ((b|b*c)d)* |d*a

Q. 4(a)Given the following grammar.

G → E

E → T + E | T

T → F * T | F

F → a

i) Is this grammar ambiguous? Explain!

ii) Draw all parse trees for sentence “a+a*a+a”. (b) Consider the following grammar.

S→ A

A→ A+A | B++

B → y

Draw parse tree for the input “y+++y++”

Q. 5(a)Explain the role of the Lexical Analyzer and Parser in detail. (b)Differentiate between Top-down parsing and Bottom-up parsing.

ASSIGNMENT No. 2

Total Marks: 100

Note: All questions carry equal marks.

Q. 1(a)Rewrite the following SDT:

A A {a} B | A B {b} | 0

B -> B {c} A | B A {d} | 1

so that the underlying grammar becomes non-left-recursive. Here, a, 6, c, and d are actions, and 0 and 1 are terminals.

(b)This grammar generates binary numbers with a "decimal" point:

S-* L . L | L

L-+LB\B

B -> 0 | 1

Design an L-attributed SDD to compute S.val, the decimal-number value of an input string. For example, the translation of string 101.101 should be the decimal number 5.625.

Q. 2(a)Translate the following expressions using the goto-avoiding translation scheme.

i)if (a==b kk c==d |I e==f) x == 1;

ii)if (a==b II c==d || e==f) x == 1;

iii)if (a==b && c==d kk e==f) x == 1;

(b)Construct the DAG and identify the value numbers for the sub expressions of the following expressions, assuming + associates from the left.

i) a + b+ (a + b).

ii) a + b + a + b.

iii) a + a + ((fl + a + a + (a + a + a + a )).

Q. 3(a)Explain the following

i)Back Patching

ii)Procedure Calls

(b)Generate code for the following three-address statements, assuming all variables are stored in memory locations. i) x = 1

ii) x = a

iii) x = a + 1

iv) x = a + b

v) The two statements

x = b * c

y = a + x

Q. 4(a)The programming language C does not have a Boolean type. Show how a C compiler might translate if-statement into three-address code.

(b)Construct the DAG for the basic block

d = b * c

e = a + b

b = b * c

a = e - d

Q. 5(a)Generate code for the following three-address statements assuming a and b are arrays whose elements are 4-byte values.

i)The four-statement sequence

x = a [ i]

y = b [ j]

a [ i ] = y

b [ j ] = x

ii) The three-statement sequence

x = a [ i]

y = b [ i]

z = x * y

iii) The three-statement sequence

x = a [ i]

y = b[x]

a [ i ] = y

(b)Suppose a...