Compilers

Which program error can be detected at compile time?

  1. AAn error because a file the user specified does not exist
  2. BAn error from running out of available memory during execution
  3. 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.
Practice this topic Back to topic

More Compilers questions

  1. What is the main benefit of compile-time type checking in a statically typed language?
  2. What is commonly used to express the rules for recognizing tokens in lexical analysis?
  3. Which kind of grammar is used to describe most programming languages and underlies parsing?
  4. What does the abstract syntax tree for the expression 2 + 3 * 4 look like?
  5. Which describes three-address code, a kind of intermediate representation?