UNIT III
UNIT III
SET A
Column A Column B
1. Synthesized Attributes a) Depend on child nodes
2. Syntax Tree b) Intermediate representation
3. Type Checking c) Ensures compatibility of types
4. Static Type Checking d) Performed at compile time
5. Dynamic Type Checking e) Performed during execution
Answer:
1 - a, 2 - b, 3 - c, 4 - d, 5 - e
css
Copy code
t1 = a + b
t2 = t1 * c
SET B
Fill in the Blanks:
Column A Column B
a) Representing expressions and statements in an
1. Syntax Tree
intermediate form
b) Ensures operations are applied to compatible
2. Type Checking
types
c) Intermediate representation of code used for
3. Three Address Code
optimization
4. Translation of d) Conversion of expressions into machine-
Expressions compatible code
5. Syntax Directed e) Defines the translation of a language using
Definitions (SDDs) semantic rules
Answer:
True or False:
SET C
I. Fill in the Blanks:
Column A Column B
a) Intermediate representation for program
1. Syntax Tree
optimization
b) Ensures variables are used with compatible
2. Type Checking
data types
c) Represents the hierarchical structure of a
3. Three Address Code
program
d) Determines the order of applying semantic
4. Evaluation Order
actions
5. Syntax Directed Definitions e) Associates semantic actions with grammar
(SDDs) productions
Answer:
IV.True or False:
1. Syntax Directed Definitions (SDDs) are used to define the lexical rules of
a language.
Answer: False
2. Three Address Code is a low-level intermediate representation that is
close to machine code.
Answer: True
3. Type Checking is only concerned with verifying that variables are
declared in the source program.
Answer: False
4. The Evaluation Order in Syntax Directed Definitions affects the
sequence of applying semantic rules during code generation.
Answer: True
5. Syntax Trees are used in a compiler to represent the tokenization of
source code.
Answer: False
1. What are Syntax Directed Definitions (SDDs) and how are they
used in compilers?
Answer: Syntax Directed Definitions (SDDs) are a set of rules used in
compilers to associate semantic actions with grammar rules. They guide
the translation of a program from its syntax to intermediate or machine
code, with each production in the grammar having a semantic rule that
specifies how to compute or generate code.
2. What is Three Address Code and why is it considered an important
intermediate representation in compilers?
Answer: Three Address Code (TAC) is an intermediate representation
used in compilers where each instruction typically involves one
operator and up to three operands. It simplifies optimization and
transformation to machine code, as it provides a simple, linear
representation of the program's logic, facilitating easier manipulation.
3. Explain the concept of Type Checking in a compiler.
Answer: Type checking is the process in a compiler where the types of
variables and expressions are verified to ensure that operations are
applied correctly according to the language's type system. This process
helps prevent type errors such as adding an integer to a string and
ensures that the program adheres to its type rules.
4. What is the role of Evaluation Order in Syntax Directed
Definitions?
Answer: The evaluation order in Syntax Directed Definitions specifies
the sequence in which semantic rules are applied to a syntax tree. This
order is crucial for correctly generating intermediate code or
performing computations, ensuring that dependent expressions or
variables are handled before they are used.
5. How does a Syntax Tree help in the compilation process?
Answer: A Syntax Tree represents the hierarchical structure of a
program, where each node corresponds to a construct in the source
code. It helps in understanding the program's syntactic structure and is
used in subsequent stages like type checking, optimization, and code
generation.
SET D
Column A Column B
1. Syntax Tree a) Ensures type safety during translation
b) Intermediate representation used for
2. Type Checking
optimization
3. Three Address Code c) Hierarchical representation of a program
4. Syntax Directed d) Associates semantic actions with grammar
Definition (SDD) rules
5. Translation of e) Converts expressions to intermediate form for
Expressions easier translation
Answer:
IV.True or False:
SET - E
Column A Column B
1. Syntax Directed
a) Simplifies the intermediate code generation
Definition
b) Ensures compatibility of data types during
2. Three Address Code
compilation
3. Type Checking c) Defines translation actions for grammar rules
d) Represents the hierarchical structure of a
4. Syntax Tree
program
e) A platform-independent representation of the
5. Intermediate Language
program
Answer:
IV.True or False:
1. What are Syntax Directed Definitions (SDDs), and why are they
important in the compilation process?
Answer: Syntax Directed Definitions (SDDs) are a set of rules that
associate semantic actions with grammar productions. These actions
guide the translation of source code into intermediate or machine code,
allowing the compiler to process the syntax of the language while
applying appropriate semantic rules for translation, type checking, and
optimization.
2. Explain the concept of Three Address Code and its significance in a
compiler's intermediate code generation.
Answer: Three Address Code (TAC) is an intermediate representation
used in compilers, where each instruction consists of a single operator
and at most three operands. TAC simplifies the translation of
expressions and allows for easier optimization, as it breaks down
complex expressions into smaller, more manageable instructions.
3. What is the role of type checking in a compiler, and how does it
prevent errors during the compilation process?
Answer: Type checking ensures that operations in a program are
performed on operands of compatible data types, preventing type
errors such as adding an integer to a string. It helps the compiler verify
that the program adheres to the specified type rules of the language,
reducing the likelihood of runtime errors.
4. How does a Syntax Tree assist in the generation of intermediate
code in a compiler?
Answer: A Syntax Tree represents the hierarchical structure of a
program, where each node corresponds to a language construct (e.g., an
expression or statement). It is used during the intermediate code
generation phase to break down the program into smaller, manageable
parts, making it easier to generate optimized code and detect semantic
errors.
5. What is an intermediate language, and why is it used in compilers?
Answer: An intermediate language is a representation of a program
that lies between the high-level source code and machine code. It is used
in compilers to provide a platform-independent form of the program
that can be easily optimized before being translated into machine-
specific code, ensuring efficiency and portability.