Chapter 4: Syntax Analysis

Panic mode .

. Consider following code

begin

a = b + c;

x = p r ;

h = x < 0;

end;

. The second expression has syntax error

. Panic mode recovery for begin-end block skip ahead to next ';' and try to parse the next expression

. It discards one expression and tries to continue parsing

. May fail if no further ';' is found

Consider the code shown in the example above. As we can see, the second expression has a syntax error. Now panic mode recovery for begin-end block states that in this situation skip ahead until the next ' ; ' is seen and try to parse the following expressions thereafter i.e., simply skip the whole expression statement if there is an error detected. However, this recovery method might fail if no further ' ; ' is found. While panic-mode correction often skips a considerable amount of input without checking it for additional errors, it has the advantage of simplicity and, unlike some other methods to be considered later, it is guaranteed not to go into an infinite loop. In situations where multiple errors in the same statement are rare, this method may be quite adequate.