0% found this document useful (0 votes)
20 views2 pages

3a) Assignment 2

This document is an assignment for the B.Tech program in Computer Science and Engineering at ITER, Siksha 'O' Anusandhan University, focusing on Programming Languages and Compilers. It includes various theoretical questions related to grammar, parsing techniques, syntax-directed translation, and code generation. The assignment aims to evaluate students' understanding and application of compiler design principles and related concepts.

Uploaded by

Milind Jha
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
20 views2 pages

3a) Assignment 2

This document is an assignment for the B.Tech program in Computer Science and Engineering at ITER, Siksha 'O' Anusandhan University, focusing on Programming Languages and Compilers. It includes various theoretical questions related to grammar, parsing techniques, syntax-directed translation, and code generation. The assignment aims to evaluate students' understanding and application of compiler design principles and related concepts.

Uploaded by

Milind Jha
Copyright
© © All Rights Reserved
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

ITER, SIKSHA ‘O’ ANUSANDHAN Assignment

(Deemed to be University)

Computer Science & Engineering, Computer


Branch Programme B.Tech
Science and Information Technology
Course Name Programming Languages and Compilers Semester VI
Course Code CSE4021 Academic Year 2023
Theory Assignment - 2 Topic: Programming Languages and Compilers
Learning Level L1: Remembering L3: Applying L5: Evaluating
(LL) L2: Understanding L4: Analysing L6: Creating
Q’s Questions COs LL
a) Show the following grammar : [ GATE-2014]
S→ SA | A
A→ a
is SLR(1) but not LL(1).
b) The following is an ambiguous grammar:
S→AS|b
1 A→SA|a CO3 L2,L3
Construct the cannonical sets of LR(0) items for this grammar. If you try to
build an LR-parsing table for this grammar, there are certain conflicting
acrtions.What are they? Suppose you tried to use the parsing table by
nondeterministically choosing a possible action whenever there is a conflict.
Show all the possible sequences of actions on input abab
.

Construct the canonical LR and LALR sets of items for the grammar
2 S → SS + | SS* | a CO3 L3
Show that the following grammar: [ GATE-2016]
S → Aa | bAc | Bc | bBa
3 A→d CO3 L3
B→d
is LR(1) but not LALR(1).
Define the SDT for the evaluation of the following arithmetic expressions and, also
show the annotated parse trees. [ n is the end marker of the expression]
4 CO4 L1, L2
a) (9 + 8 * (7 + 6 ) + 5 ) * 4 n
b) (3+ 4)* (5 + 6 ) n
The following grammar generates binary numbers with a “decimal” point:
S→L . L | L
L→ L B | B
5 B→0|1
CO4
Construct an L-attributed SDD to compute S. val, the decimal-number value of an L3
input string. For example, the translation of string 101.101 should be the decimal
number 5.625. Hint: use an inherited attribute L. side that tells which side of the
decimal point a bit is on.
Suppose that we have a production A → BCD.Each of the four nonterminals A, B,
C and D have two attributes: s is a synthesized attribute and i is an inherited
attribute. For each of the sets of rules below, analyze and tell whether (i) the rules
are consistent with an S-attributed definition (ii) the rules are consistent with an L-
attributed definition, and (iii) whether the rules are consistent with any evaluation
L4
6 order at all? CO4
a) A.s= B.i + C.s
b) A.s= B.i + C.s and D.i = A.i + B.s
c) A.s= B.s + D.s
d) A.s =D.i, B.i = A.s +C.s , C.i =B.s and D.i = B.i +C.i

a) Construct the DAG for the expression L3


7 CO5
(( x + y) – (( x + y) * (x – y ))) + (( x + y ) * ( x – y))
b) Translate the arithmetic expression a + -(b+c) into: a syntax tree,
quadruples, triples, and indirect triples.
Consider the intermediate code given below: [ GATE 2015]
1. i = 1
2. j = 1
3. t1 = 5 * i
4. t2 = t1 + j
5. t3 = 4 * t2
6. t4 = t3 L3
8 CO5
7. a[t4] = –1
8. j = j + 1
9. if j <= 5 goto (3)
10. i = i + 1
11. if i < 5 goto (2)
Construct the control-flow-graph for the above code and, also count the
number of nodes and edges of the constructed control-flow graph.
a) Illustrate the code for the following three-address sequences
assuming a and bare arrays whose elements are 4-byte values. The
four-statement sequence:
x= a[i]
y =b[j]
a[i] = y
b[j] =x
b) Generate the code for the following sequence assuming that n is in a L2
9 memory location: CO6
s=0
i=0
L1: if i > n goto L2
s= s + i
i =i + 1
goto L1
L2:
Suppose a basic block is formed from the C assignment statements:
x = a + b + c + d + e + f;
y = a + c + e;
a) Give the three-address statements (only one addition per statement) for this
10 CO6 L2
block.
b) Use the associative and commutative laws to modify the block to use the
fewest possible number of instructions, assuming both x and y are live on
exit from the block.

Understand the principles in theory of computation and their role in designing


CO1
various stages involved in the translation process of a compiler
Acquire knowledge in different phases and passes of Compiler, and
CO2 specifying different types of tokens by lexical analyser, and able to use the
compiler tools like LEX, YACC, etc..
Understand and design Parser(s) (LL, SLR, CLR and LALR) and its types i.e.
CO3
Top-down and Bottom-up parsers.
Course Outcomes
Apply and evaluate syntax directed translation schemes, synthesized
CO4 attributes, inherited attributes, and different techniques for symbol table
organization.
Analyse the generation of various intermediate codes and the process of their
CO5
optimization.
Understand the target machine’s run time environment, its instruction set for
CO6
code generation and techniques used for code optimization.

You might also like