Compiler Design MCQ Questions And Answers - Semantic Analysis
This section focuses on "Semantic Analysis" in Compiler Design. These Multiple Choice Questions (MCQs) should be practiced to improve the Compiler Design skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. What is true about Syntax Directed Definitions?
A. Syntax Directed Definitions + Semantic rules = CFG
B. Syntax Directed Definitions + CFG = Semantic rules
C. CFG + Semantic rules = Syntax Directed Definitions
D. None of the above
View Answer
Ans : C
Explanation: CFG + semantic rules = Syntax Directed Definitions
2. Which of the following error is expected to recognize by semantic analyzer?
A. Type mismatch
B. Undeclared variable
C. Reserved identifier misuse.
D. All of the above
View Answer
Ans : D
Explanation: We have mentioned some of the semantics errors that the semantic analyzer is expected to recognize: Type mismatch, Undeclared variable, Reserved identifier misuse, Multiple declaration of variable in a scope, Accessing an out of scope variable, Actual and formal parameter mismatch.
3. ____________ is a medium to provide semantics to the context-free grammar
A. Domain grammer
B. Attribute grammar
C. Object grammer
D. Value grammer
View Answer
Ans : B
Explanation: Attribute grammar is a medium to provide semantics to the context-free grammar and it can help specify the syntax and semantics of a programming language.
4. Semantic analyzer attaches attribute information with AST, which are called?
A. Analyzer attribute
B. Attributed AST
C. Analyzer AST
D. AST
View Answer
Ans : B
Explanation: Semantic analyzer attaches attribute information with AST, which are called Attributed AST.
5. Which attributes get values from the attribute values of their child nodes?
A. Synthesized attributes
B. Inherited attributes
C. S-attributed SDT
D. L-attributed SDT
View Answer
Ans : A
Explanation: Synthesized attributes : These attributes get values from the attribute values of their child nodes.
6. Which form of SDT uses both synthesized and inherited attributes with restriction of not taking values from right siblings?
A. T-attributed SDT
B. A-attributed SDT
C. S-attributed SDT
D. L-attributed SDT
View Answer
Ans : D
Explanation: L-attributed SDT : This form of SDT uses both synthesized and inherited attributes with restriction of not taking values from right siblings.
7. If an SDT uses only synthesized attributes, it is called as?
A. T-attributed SDT
B. A-attributed SDT
C. S-attributed SDT
D. R-attributed SDT
View Answer
Ans : C
Explanation: If an SDT uses only synthesized attributes, it is called as S-attributed SDT.
8. Which of the following tasks should be performed in semantic analysis?
A. Scope resolution
B. Type checking
C. Array-bound checking
D. All of the above
View Answer
Ans : D
Explanation: The following tasks should be performed in semantic analysis: Scope resolution, Type checking, Array-bound checking.
9. What is meant by compositional semantics?
A. Determining the meaning
B. Logical connectives
C. Semantics
D. All of the above
View Answer
Ans : A
Explanation: Compositional semantics is the process of determining the meaning of P*Q from P, Q and *.
10. What is true about Attribute Grammar?
A. Attribute grammar is a special form of context-free grammar
B. Each attribute has well-defined domain of values
C. The right part of the CFG contains the semantic rules
D. All of the above
View Answer
Ans : D
Explanation: all of the above statement are true.
Discussion