Q.1 What is Syntax-Directed Translation primarily used for in compiler design?
Code optimization
Error detection
Generating intermediate code
Memory allocation
Explanation - Syntax-Directed Translation is a method in compiler design where translation rules are associated with grammar productions to generate intermediate representations.
Correct answer is: Generating intermediate code
Q.2 In Syntax-Directed Translation, semantic rules are associated with:
Tokens
Productions
Registers
Symbol table entries
Explanation - Semantic rules are attached to grammar productions to specify translations and attribute computations.
Correct answer is: Productions
Q.3 Which of the following defines values for attributes in a Syntax-Directed Definition?
Parsing rules
Semantic rules
Symbol table entries
Intermediate code
Explanation - Semantic rules specify how attribute values are computed during parsing.
Correct answer is: Semantic rules
Q.4 An attribute that depends only on the attributes of its children in the parse tree is called:
Inherited attribute
Synthesized attribute
Dynamic attribute
Semantic attribute
Explanation - Synthesized attributes are computed from the attributes of child nodes and passed up the parse tree.
Correct answer is: Synthesized attribute
Q.5 Which type of attribute depends on parent or sibling nodes in the parse tree?
Synthesized attribute
Inherited attribute
Dynamic attribute
Static attribute
Explanation - Inherited attributes are defined based on the values from parent or sibling nodes.
Correct answer is: Inherited attribute
Q.6 An S-attributed definition uses only:
Inherited attributes
Synthesized attributes
Dynamic attributes
Lexical attributes
Explanation - S-attributed definitions rely solely on synthesized attributes, making them easier to implement.
Correct answer is: Synthesized attributes
Q.7 What is the key feature of an L-attributed definition?
Uses only synthesized attributes
Allows both inherited and synthesized attributes
Requires bottom-up parsing
Does not use semantic rules
Explanation - L-attributed definitions allow both inherited and synthesized attributes but with restrictions to maintain left-to-right evaluation.
Correct answer is: Allows both inherited and synthesized attributes
Q.8 What is a Syntax-Directed Definition (SDD)?
A grammar without terminals
A grammar with semantic rules attached
A parsing table generator
A code optimizer
Explanation - An SDD is a context-free grammar where each production has semantic rules specifying how to compute attributes.
Correct answer is: A grammar with semantic rules attached
Q.9 Which of the following is true about dependency graphs in SDD?
They detect parsing errors
They ensure correct attribute evaluation order
They represent code generation
They optimize symbol table lookup
Explanation - Dependency graphs show how attributes depend on each other and help schedule evaluations.
Correct answer is: They ensure correct attribute evaluation order
Q.10 A parse tree with annotated attribute values is called:
Syntax tree
Annotated parse tree
Semantic table
Evaluation tree
Explanation - When attributes are attached to parse tree nodes, it forms an annotated parse tree.
Correct answer is: Annotated parse tree
Q.11 Which attribute type can be easily evaluated in bottom-up parsing?
Synthesized attributes
Inherited attributes
Static attributes
Dynamic attributes
Explanation - Synthesized attributes naturally flow up the parse tree, making them easier for bottom-up evaluation.
Correct answer is: Synthesized attributes
Q.12 Which parsing technique is more suitable for L-attributed definitions?
Top-down parsing
Bottom-up parsing
Operator precedence parsing
Backtracking parsing
Explanation - Top-down parsing works well for L-attributed definitions since evaluation proceeds left-to-right.
Correct answer is: Top-down parsing
Q.13 What is the purpose of attaching actions to grammar rules in Syntax-Directed Translation?
Error detection
Intermediate code generation
Symbol table maintenance
All of the above
Explanation - Semantic actions can perform tasks such as error detection, code generation, and symbol table management.
Correct answer is: All of the above
Q.14 Which of the following is NOT a valid application of Syntax-Directed Translation?
Type checking
Code generation
Lexical analysis
Intermediate representation creation
Explanation - Lexical analysis is handled by lexical analyzers, not syntax-directed translation.
Correct answer is: Lexical analysis
Q.15 A translation scheme is different from an SDD because:
It uses only synthesized attributes
It embeds semantic actions within productions
It avoids semantic rules
It only generates code
Explanation - Translation schemes directly place semantic actions into the grammar rules.
Correct answer is: It embeds semantic actions within productions
Q.16 Which of the following helps to detect circular dependencies in attribute evaluation?
Parse trees
Dependency graphs
Symbol tables
Intermediate code
Explanation - Dependency graphs reveal circular dependencies by showing attribute dependencies.
Correct answer is: Dependency graphs
Q.17 If all attributes in an SDD are synthesized, the evaluation order is:
Top-down only
Bottom-up only
Independent of parsing order
Must be left-to-right
Explanation - S-attributed definitions rely solely on synthesized attributes, which suit bottom-up evaluation.
Correct answer is: Bottom-up only
Q.18 Which type of grammar is typically used with Syntax-Directed Translation?
Context-free grammar
Regular grammar
Unrestricted grammar
Context-sensitive grammar
Explanation - Syntax-Directed Translation works by associating semantic rules with productions of context-free grammar.
Correct answer is: Context-free grammar
Q.19 In an L-attributed definition, inherited attributes can depend on:
Parent attributes only
Siblings' attributes to the left
Children attributes
All nodes in the tree
Explanation - L-attributed definitions allow inherited attributes to depend on parent attributes and left siblings.
Correct answer is: Siblings' attributes to the left
Q.20 Which structure helps to determine if attribute evaluation is possible without ambiguity?
Symbol tables
Dependency graphs
Parse stack
Code generator
Explanation - Dependency graphs ensure evaluation can proceed without ambiguity or circular dependencies.
Correct answer is: Dependency graphs
Q.21 What is the main difficulty with inherited attributes in bottom-up parsing?
They cannot be evaluated until children are parsed
They depend on right siblings
They require circular dependencies
They increase parse tree height
Explanation - Inherited attributes may need values from right siblings, which bottom-up parsers cannot access easily.
Correct answer is: They depend on right siblings
Q.22 Which of the following can be represented by syntax-directed translation?
Type checking
Intermediate code generation
Storage allocation
All of the above
Explanation - Syntax-directed translation is versatile, handling type checking, code generation, and storage allocation.
Correct answer is: All of the above
Q.23 What kind of attributes are convenient for top-down parsing strategies?
Synthesized attributes
Inherited attributes
Dynamic attributes
Lexical attributes
Explanation - Inherited attributes are passed down from parent nodes, fitting well with top-down parsing strategies.
Correct answer is: Inherited attributes
Q.24 Which is true about translation schemes compared to SDDs?
They only use synthesized attributes
They avoid grammar productions
They embed semantic actions directly into grammar rules
They cannot be used for parsing
Explanation - Unlike SDDs, translation schemes specify actions inline within grammar productions.
Correct answer is: They embed semantic actions directly into grammar rules
Q.25 The evaluation order of attributes in an annotated parse tree is determined using:
Parsing algorithm
Topological sorting
Symbol table lookups
Lexical analyzer
Explanation - Dependency graphs are topologically sorted to determine the correct attribute evaluation order.
Correct answer is: Topological sorting
