SS-CD Assignment 3
SS-CD Assignment 3
UDAYAPURA,KANAKAPURA ROAD,BANGALORE-82
Course Outcomes:
Course Outcomes: The students should be able to:
Assignment-3
1. a). What is handle pruning? Explain with the help of the grammar SSS+|SS*|a and
input string aaa*a++. Give a bottom-up parse of the given input string.
(04 Marks, may/june 2010)
(CO4)
b). What is a shift reduce parser? Explain the conflicts that may occur during shift
reduce parsing. Show the working of a shift reduce parser for accepting id1+id2*id3,
considering the grammar;
E→E+T/T
T→T*F/F
F→id (04 Marks,June 09, June 2013, Dec 2011,june/jul 09)(CO4)
2. a). Given the grammar A→(A) | a
i. Find LR (0) items
ii. Construct SLR parsing table and write the algorithm of constructing SLR- Parsing
Table
iii. show that parsing steps for the string ((a)). (04 Marks, june/jul 09)
(CO4)
b). What is the meaning of ‘L’ and ‘R’ in LR grammars? Why LR parsing is attractive?
(2 Marks, June 2011)
c). Write an algorithm for computation of CLOSURE of LR(0). (02 Marks, Dec 2012)
3. a). Obtain first and follow symbols for the grammar S→L=R S→R L→*R L→id R→L
and obtain SLR parsing table. Is the grammar SLR? (05 Marks, Dec 09)(CO4)
b). Write a note on the lex generator and parser generator –(lex and yacc).
(03 Marks, Dec 2018)
(CO4)
4. a). Form the Action/Goto table for the following grammar
S→Aa|bAc|Ba|bBa
A→d
B→d
Justify whether the grammar is LR(0) or not. (08 Marks, june/jul 2014, June 2018)
(CO4)
b). Write an algorithm for LR Parsing. (03 Marks, Dec 2012)(CO4)
5. a). What is DAG? Explain how DAGs will help in intermediate code generation?
Construct a DAG and three address-code for the following expression, a+a*(b-c)+(b-
c)*d. Also give the sequence of steps for constructing the same.
(04 Marks, June 2011,Dec 2013, Dec 2010, Dec 09) (CO5)
b). List various three address instruction forms. Give one example for each.
(04 Marks, June 2013, Dec 2011, Dec 09) (CO5)
6. a). Write a note on quadruple, triples, static assignment form and indirect triples with an
example. (04 Marks, Dec 2011, june/jul 12) (CO5)
b).Explain the following code optimization with example:
i. Finding local common sub expression.
ii. Dead code elimination (04 Marks, June 2011, Dec 2010,
Dec 2018)
7. a). Discuss the issues in the design of a code generator.
(04 Marks, Dec 2013, Dec 09, June 2011, may/june 2010, june/jul 09) (CO5)
b). Explain in brief dead code elimination. (04 Marks, Dec 2018)
(CO5)
8. a). In target language explain
i. A simple target machine model
ii. Program and instruction cost ( 04 Marks, Dec 2013, Dec 09, June 2011)
(CO5)
b). What is a basic block? How optimization is done in basic blocks?
(04 Marks, june/jul 12, Dec 2018)(CO5)
9. a). Define inherited and synthesized attributes. Give examples.
(03 Marks, Dec 2011, june/jul 12, Dec. 09,June/july 2014)(CO5)
b). Give a SDD for desktop calculator and show its stack implementation and show
annotated parse tree for the expression (3+4)*(5+6).
(5 Marks, Dec 2013, Dec 09, Dec 2010, june 12) (CO5)
10. a). Consider the context-free-grammar given below. (05 Marks, may/june 2010) (CO5)
S→EN
E→E+T|E-T|T
T→T*F|T/F|F
F→ (E) |digit N→;
a. Obtain the SDD for the above grammar.
b. Construct the parse tree, syntax tree and annotated parse tree for the input
string 5*6+7.
b). Give SDD of a simple calculator. (03 Marks, Dec 2018)
11. a). Write annotated parse tree for expression 5 + 4 * 3n where grammar is
E→E+T|T
T→T*F|F
F→(E)|digit (04 Marks, may/june 2010)
(CO5)
b). Explain Operator Precedence Parsing with example. (04 Marks, may/june 2010) (CO4)
12. a). Construct the syntax tree for the expression x*y-5+z. (04 Marks, June 2018)(CO5)
b). Generate code for the following expression using code generator algorithm