Compilers
Which program error can be detected at compile time?
- AAn error because a file the user specified does not exist
- BAn error from running out of available memory during execution
- CA grammar error such as unmatched parentheses
Show answer and explanation
Answer: C. A grammar error such as unmatched parentheses
Grammar errors such as unmatched parentheses or a missing semicolon are always caught by the parser, stopping compilation, and type mismatches are found by semantic analysis. Whether a user-specified file exists or enough memory is available depends on the run-time environment and input, so it cannot be known at compile time. Such run-time errors require checks in the program, such as testing return values.
- A. Whether the file exists depends on the run-time environment.
- B. Whether memory suffices is determined at run time.
- C. Correct. Grammar errors are caught by the parser.