0% found this document useful (0 votes)
17 views7 pages

CS3501 CD Qb-Unit 3

CS3501 CD QB-UNIT 3

Uploaded by

paviganesh8789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

CS3501 CD Qb-Unit 3

CS3501 CD QB-UNIT 3

Uploaded by

paviganesh8789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 7

DEPARTMENT OF COMPUTING TECHNOLOGIES

Name of the Faculty Member : Mrs.R.PAVITHRA


Designation and Department : ASSISTANT PROFESSOR / CT
Academic Year : 2024-2025(ODD)
Class : III -CSE
Subject with Code & Name : CS3501 – COMPILER DESIGN
QUESTION BANK
UNIT-III

SYNTAX DIRECTED TRANSLATION & INTERMEDIATE CODE


GENERATION

PART – A
1. What is meant by backpatching? (Nov/Dec 2023)
Backpatching is a technique used in compiler design for managing the generation
of intermediate code, especially in the context of handling control flow statements
such as loops and conditional statements
2. What is meant by type checking? (Nov/Dec 2023)
Type checking is a process in programming language compilers and interpreters
that ensures that the operations in a program are performed on compatible data types.
This process can occur at various stages of program execution
3. Write three address code sequence for the assignment Statement.
(Nov/Dec 2021)
d := (a −b) + (a − c) + (a − c).
t1:=a−b
t2:=a−ct2 := a - ct2:=a−c
t3:=t1+t2t3 := t1 + t2t3:=t1+t2

Page 1 of 7
t4:=t3+t2t4 := t3 + t2t4:=t3+t2
d:=t4d := t4d:=t4
4. How do you identify predictive parser and non-recursive
predictive parser?
(Nov/Dec 2021)
A predictive parser is a type of top-down parser for a subset of context-free
grammars, typically LL(1) grammars. These parsers use a lookahead symbol to
make parsing decisions and do not involve backtracking.

A non-recursive predictive parser is a type of predictive parser that uses a stack and
parsing table instead of recursive procedures. This makes it iterative rather than
recursive.

5. What are the properties of optimizing compiler?


Optimizing compiler is a type of compiler that aims to improve the performance
and efficiency of the generated code without altering its output. The main goal is to
generate code that runs faster, uses fewer resources, or consumes less power.
6. What are the various methods of implementing three address statements?
(May/June 2013)
There are three types of intermediate representation:-

1. Syntax Trees
2. Postfix notation
3. Three Address Code
7. Write the semantic action for the production rule of E ->E1 OR M
E2. E -> E1 OR M E2 { E.value = E1.value || E2.value;
(Nov/Dec 2020)

8. Translate the arithmetic expression x = (a + b)∗– c/d into


quadruples and triples. .
(Nov/Dec 2020)

Location Operator arg 1 arg 2 Result

(0) + a b t1

(1) − t1 t2

(2) + c d t3

(3) ∗ t2 t3 t4

Page 2 of 7
Location Operator arg 1 arg 2 Result

(4) + t1 c t5

(5) − t4 t5 t6

9. Translate the arithmetic expression a * -(b+c) into syntax tree and postfix
notation. (Nov/Dec 2021)

Postfix Notation: a b c uminus * b c uminus * + assign

10. Construct a decorated parse tree according to the syntax directed definition
for the following input statement: (4+7.5*3)/2. (Apr/ May 2015)

11. Write the 3-address code x=*y ; a=&x, A/ M’2015


x:=*y MOV *Ry, x
a:=&x MOV &Rx, a
12. Write down syntax Directed definition of a simple desk calculator
(Nov / Dec 2016)
Syntax Directed Definition (SDD) is a kind of abstract specification. The
combination of context free grammar and semantic rules

13. What are synthesized attributes? (Nov/Dec 2015)


a. Synthesized Attributes. They are computed from the values of the
attributes of the children nodes.
Page 3 of 7
b. Inherited Attributes. They are computed from the values of the attributes
of both the siblings and the parent nodes.

14. Mention the rules for type checking (April / May 2016)
A compiler must check that the source program should follow the syntactic and
semantic conventions of the source language and it should also check the type rules
of the language.
15. Write down syntax directed definition of a simple desk calculator.
(Nov / Dec 2016)

16. Define syntax directed definition.


 Syntax Directed Definitions are a generalization of context-free grammars in
which:
1. Grammar symbols have an associated set of Attributes;
2. Productions are associated with Semantic Rules for computing the values of
attributes.
 Such formalism generates Annotated Parse-Trees where each node of the
tree is a record with a field for each attribute (e.g., X.a indicates the attribute
a of the grammar symbol X).

17. Define S-Attributes.


S-Attributed Definitions

Definition : An S-Attributed Definition is a Syntax Directed Definition that uses


only synthesized attributes.
• Evaluation Order. Semantic rules in a S-Attributed Definition can be evaluated
by a bottom-up, or Post Order, traversal of the parse-tree.
• Example. The above arithmetic grammar is an example of an S-Attribute
d Definition. The annotated parse-tree for the input 3*5+4n is:

Page 4 of 7
18. Define Dependency Graph.
• Dependency Graphs are the most general technique used to evaluate syntax
directed definitions with both synthesized and inherited attributes.
• A Dependency Graph shows the interdependencies among the attributes of
the various nodes of a parse-tree.
– There is a node for each attribute;
– If attribute b depends on an attribute c there is a link from the node for c to
the node for b ( b ← c).
• Dependency Rule: If an attribute b depends from an attribute c, then we need
to fire the semantic rule for c first and then the semantic rule for b.

19. Mention the two rules of type checking ( NOV/DEC 2011)


a. A type checker verifies that the type of a construct matches that expected by
its context.
b. Type information gathered by a type checker may be needed when code is
generated.

20. What is the significance of intermediate code? (MAY/JUNE 14, APRIL/MAY


11, APRIL/MAY)
 Retargeting is facilitated; a compiler for a different machine can be
created by attaching a back end for the new machine to an existing front
end.
 A machine-independent code optimizer can be applied to the intermediate
representation.

PART – B
1. Explain dangling-else problem with an example and give the unambiguous
grammar for the same (Nov/Dec 2020)
2. Below is a grammar for expressions involving operator + and integer or

Page 5 of 7
floating-point operands. Floating-point numbers are distinguished by having
a decimal point. (Nov/Dec 2020)

E -> E + T|T
T -> num.num | num
i) Give an Syntax Directed Definition (SDD) to determine the type of each
term T and expression E.
ii) Extend your SDD of (i) to translate expressions into postfix notation. Use
the binary operator intToFloat to turn an integer into an equivalent float.

iii) Give an SDD to differentiate expressions such as x∗(3∗x + x∗x) involving

the operators + and ∗, the variable x, and constants. Assume that no

simplification occurs, so that, for example, 3 ∗ x will be translated into

3∗1+0∗x

3. Write the syntax directed translation scheme with backpatching to generate


three address code for the given grammar. (Nov/Dec 2020)
S → while E do S | begin L end
L → L; S | S
E → E or E | E and E | not E | id4.
4. Construct a Syntax-Directed Translation scheme that translates arithmetic
expressions from infix into postfix notation. Your solution should include
the context-free grammar, the semantic attributes for each of the grammar
symbols and semantic rules. Show the application of your scheme to the

input string “3 ∗ 4 + 5 ∗ 2”. (Nov/Dec


2020/2021)
5. Explain in detail about design of predictive translator. ( Nov/Dec 2023)
6. Discuss the address code and its implementation with example (Nov/Dec 2023)
7. Describe about the contents of activation record and create a parse trees for the
following string : string id + id – id and check whether the string is ambiguous or
not. (Nov/Dec 2021)

Page 6 of 7
8. Explain in detail about Specification of a simple type checker. (Apr / May 2017)
9. Write the syntax directed translation scheme with backpatching to generate
three address code for the given grammar. (13)
S → while E do S | begin L end
L → L; S | S
E → E or E | E and E | not E | id
10. Create variants of Syntax tree. Explain in detail about it with suitable examples

STAFF INCHARGE HOD

Page 7 of 7

You might also like