Questions: Semantic Analysis Phase

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A program passes the parser successfully but fails during semantic analysis. Which of the following is the most likely cause?

AThe program has a syntax error — a missing semicolon or mismatched brace
BThe program uses a variable that was never declared in the current scope
CThe program has an infinite loop that the compiler detected
DThe program uses an unsupported keyword not in the grammar
Question 2 Multiple Choice

During semantic analysis, type checking proceeds bottom-up through the AST. Which of the following best explains why this direction is correct?

ABottom-up processing is faster than top-down, which is why compilers prefer it
BTypes of composite expressions depend on the types of their subexpressions — you must know the parts before you can determine the whole
CThe symbol table is built top-down, so type checking must go in the opposite direction to avoid conflicts
DTop-down type checking would require the compiler to know the expected type before reading the expression, which is only needed for type inference
Question 3 True / False

Semantic analysis can catch most runtime errors, so a program that passes semantic analysis will execute without errors.

TTrue
FFalse
Question 4 True / False

The output of semantic analysis is the same AST produced by the parser, since semantic analysis mainly checks for errors without modifying the tree.

TTrue
FFalse
Question 5 Short Answer

What is the role of the symbol table during semantic analysis, and what two types of errors does it enable the compiler to detect?

Think about your answer, then reveal below.