Chapter 4: Syntax Analysis

Error handling

. Stop at the first error and print a message

- Compiler writer friendly

- But not user friendly

. Every reasonable compiler must recover from errors and identify as many errors as possible

. However, multiple error messages due to a single fault must be avoided

. Error recovery methods

- Panic mode

- Phrase level recovery

- Error productions

- Global correction

Error handling and recovery is also one of the important tasks for a compiler. Errors can occur at any stage during the compilation. There are many ways in which errors can be handled. One way is to stop as soon as an error is detected and print an error message. This scheme is easy for the programmer to program but not user friendly. Specifically, a good parser should, on encountering a parsing error, issue an error message and resume parsing in some way, repairing the error if possible. However, multiple error messages due to a single fault are undesirable and tend to cause confusion if displayed. Error recovery is thus a non trivial task. The following error recovery methods are commonly used:

1. Panic Mode

2. Phrase level recovery

3. Error productions

4. Global correction