Compilers

Which is the best example of an error found during semantic analysis?

  1. AAssigning a value of an incompatible type to an integer variable
  2. BForgetting the semicolon at the end of a statement
  3. CA division by zero occurring partway through when the program is run
Show answer and explanation

Answer: A. Assigning a value of an incompatible type to an integer variable

Semantic analysis examines programs that are grammatically well formed, checking that types match, that no undeclared names are used and that function calls pass the right number of arguments. Assigning an incompatible type is a typical error caught here. A missing semicolon is a grammar error found by the parser. Division by zero occurs only when the program runs and generally cannot be detected by the compiler.

  • A. Correct. Type mismatches are found by semantic analysis.
  • B. A missing semicolon is a grammar error found by the parser.
  • C. Division by zero is a run-time error.
Practice this topic Back to topic

More Compilers questions

  1. Which describes an abstract syntax tree (AST)?
  2. What is the main advantage of using an intermediate representation (IR), independent of both source language and CPU, inside a compiler?
  3. Which describes a basic block?
  4. In a control-flow graph, what do the nodes and edges represent?
  5. Which is a characteristic of an IR in SSA form?