Compilers
Which is the best example of an error found during semantic analysis?
- AAssigning a value of an incompatible type to an integer variable
- BForgetting the semicolon at the end of a statement
- 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.