The document is an assignment for Compiler Design (BCS-602) that covers various topics including intermediate code categories, three-address code translations, basic blocks, synthesized and inherited attributes, syntax directed translation schemes, and semantic rules for grammar. It includes specific tasks such as translating expressions into quadraples and triples, constructing parse trees, and generating three-address statements for given program segments. Additionally, it discusses loop optimization techniques and the design issues of code generators.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
4 views
CD Assignment
The document is an assignment for Compiler Design (BCS-602) that covers various topics including intermediate code categories, three-address code translations, basic blocks, synthesized and inherited attributes, syntax directed translation schemes, and semantic rules for grammar. It includes specific tasks such as translating expressions into quadraples and triples, constructing parse trees, and generating three-address statements for given program segments. Additionally, it discusses loop optimization techniques and the design issues of code generators.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
Compiler Design (BCS-602)
Assignment No.-03 1. Attempt all parts of the following: (a) Explain the following categories of intermediate code: (i) Three-address codes (ii) Quadruples (iii) Triples
(b) Translate the expression:
A: = -B* (c+d)| E Into Quadruples and Triples representation. (c) What is a basic block? How can a sequence of three-address statements be transformed into a list of basic blocks? Show it with examples.
(d) What are Synthesized and Inherited attributes?
2. Attempt all parts of the following:
(a) Describe various representation of three-address codes. Translate the expression: A= -(a+b)* (c+d)+(a+b+c) Into Quadruples and Triples. (b) Consider the following SDTS (syntax directed translation scheme): E E1 *T {E.val=E1.val*T.val} E T {E.val=T.val} T T1-F {T.val=T1.val-F.val} T F {T.val=F.val} F 2 {F.val=2} F 4 {F.val=4} (i) Using the above SDTS, construct a parse tree for the expression : 4-2-4*2 , Also compute its E.val. (ii) Modify the given SDTS, without changing the grammar, by introducing E.red (synthesized attribute) to count the number of reduction performed while reducing an input to E. (c) Explain the back-patching. Also generate three-address code for the following program segment: While (a < c and b > d) do If a = 1 then c = c + 1; Else While a < = d do A = a + 3; (d) Write SDT for postfix of expression- G: E → E+T /T T → T*F /F F → num 3. Attempt all parts of the following : (a) Consider the grammar (G: E E+T\T T T*F\F F (E)\id) Associate semantic rules with the production for Construction of syntax tree for an expression. Using the translation scheme construct the syntax tree for the expression: a+b *c. (b) Translate the following program segment into three-address statements : Switch ( a+ b) { Case 2 : { x = y : break;} Case 5 : {switch (X) { Case 0 : { a = b + 1; break;} Case 1 : { a = b + 3; break;} Default : { a = 2 : } } Break; Case 9 : { x = y - 1 ; break; } Default : {a = 2 ; } }
4. Translate the following program fragment into three address code :
Int i ; I = 1 While a < 10 do If x > y then a = x + y Else a = x - y 5. Attempt all parts of the following : (a) Write the semantic rules to be specified in the following infix expression grammar such that it generates corresponding postfix in the process of parsing the infix expression. The rules are E E+ T/E –T/T T 0/1/2/…/9 Also show the steps of execution through an annotated parse tree by considering the expression 3+2-4. (b) Consider the following grammar : S L:=E E E + E/L L id\[E]\id Write semantic actions for each grammar Productions to generate three address code. Generate three address code for the statement X[i] : =y+ z. (c) Write the quadruples, triples and indirect triples for the following expression : (x + y) * (y + z ) + (x + y + z). (d) Discuss the different types of Intermediate code generation. 6. Explain in detail about loop optimization. 7. Explain the following: (i) Copy Propagation (ii) Dead-Code Elimination (iii) Code Motion (iv) Reduction in Strength. 8. Define a DAG. Construct a DAG for the expression: p+p*(q-r)+(q-r)*s 9. Discuss about designing issues of code generator. 10. What is difference between S-attributed and L-attributed?