chapter 4 - 6 Flashcards
Semantic analysis checks the source program for syntactic errors.
False
Type checking ensures that operators are used with operands of permitted types.
t
A semantic analyzer can identify undeclared variables.
True
Syntax-directed translation involves both semantic rules and syntax rules.
True
Synthesized attributes depend on the attributes of the parent node.
False
Inherited attributes can be evaluated using a bottom-up traversal of the parse tree.
f
A topological sort of a dependency graph helps in determining the evaluation order of attributes.
t
Dynamic checks are performed during the execution of the program.
t
L-attributed grammars use only synthesized attributes.
f
Which of the following is a task performed during semantic analysis?
A. Lexical analysis
B. Type checking
C. Token generation
D. Code optimization
Answer: B
Semantic errors include:
A. Type mismatch
B. Syntax errors
C. Token errors
D. Memory allocation errors
Answer: A
What is the primary purpose of syntax-directed translation?
A. To optimize machine code
B. To guide the translation of source code using context-free grammars
C. To generate lexical tokens
D. To perform runtime error checking
Answer: B
In syntax-directed translation, what is the role of the parse tree?
A. To optimize the source code
B. To perform lexical analysis
C. To direct semantic analysis and intermediate code translation
D. To generate machine code
Answer: C
What is an attributed grammar?
A. A grammar that generates parse trees
B. A grammar that includes information to control semantic analysis and translation
C. A grammar used only for lexical analysis
D. A grammar used for error handling
Answer: B
- we can augment the CFG with information to control the semantic analysis and translation process.
In syntax-directed translation, what does the set of semantic actions enclosed by { } indicate?
A. The rules for lexical analysis
B. The steps for generating machine code
C. The semantic actions performed for each production
D. The optimization steps for the source code
Answer: C
Which of the following describes the output action in syntax-directed translation?
A. Generation of intermediate code
B. Printing of an error diagnostic
C. Placement of some values in a table
D. Computation of values for variable belonging to the
compiler
E. All
E. All
What is an attributed CFG?
A. A context-free grammar without semantic rules
B. A CFG with associated semantic rules for computing attribute values
C. A CFG used for lexical analysis
D. A CFG that generates machine code
Answer: B
- found in Syntax Directed Definitions
In an attributed grammar, what does an annotated parse tree represent?
A. The syntactic structure of the source code
B. The optimized version of the source code
C. A parse tree with a field for each attribute at each node
D. The intermediate code
Answer: C
What is the purpose of semantic rules in a syntax-directed definition?
A. To check for syntax errors
B. To compute the values of attributes
C. To perform lexical analysis
D. To generate machine code
B
Which of the following is an example of a semantic rule in an attributed CFG?
A. E → E + T
B. T.v → id.v
C.E.v = E.v + T.v
D. E1.v = E2.v + T.v
Answer: D
Semantic actions in syntax-directed translation are always performed after the parse tree is completely built.
False
What is a synthesized attribute?
A. An attribute of the parent depending on the children
B. An attribute of the children depending on the parent
C. An attribute related to syntax rules
D. An attribute of the parent depending on the children and the parent node itsself
Answer: D
In a syntax-directed translation, what is typically associated with each production?
A. Tokens
B. Parse trees
C. Semantic actions
D. Intermediate code
Answer: C
Which attribute type can only depend on the parent or siblings of a node?
A. Synthesized attributes
B. Inherited attributes
C. Lexical attributes
D. Terminal attributes
Answer: B
Inherited attributes, Attribute of a node is defined in terms of Attribute values at left siblings
True.
Never right
Terminals can have _________ attributes
synthesized attributes, but not inherited attributes
A dependency graph is used to:
A. Show the syntax structure of a program
B. Determine the lexical tokens of a program
C. Show the flow of information for attribute evaluation
D. Optimize the code generation process
Answer: C
Which method evaluates L-attributed definitions by mixing post-order and pre-order traversal?
A. S-Eval
B. T-Eval
C. L-Eval
D. G-Eval
Answer: C