Previous: , Up: TC-2 Samples   [Contents][Index]


4.4.2.3 TC-2 Error Recovery

Your parser must be robust to (some) syntactic errors. Observe that on the following input several parse errors are reported, not merely the first one:

(
  1;
  (2, 3);
  (4, 5);
  6
)

File 4.17: multiple-parse-errors.tig

$ tc multiple-parse-errors.tig
error→multiple-parse-errors.tig:3.5: syntax error, unexpected ",", expecting ;
error→multiple-parse-errors.tig:4.5: syntax error, unexpected ",", expecting ;
⇒3

Example 4.20: tc multiple-parse-errors.tig

Of course, the exit status still reveals the parse error. Error recovery must not break the rest of the compiler.

$ tc -XA multiple-parse-errors.tig
error→multiple-parse-errors.tig:3.5: syntax error, unexpected ",", expecting ;
error→multiple-parse-errors.tig:4.5: syntax error, unexpected ",", expecting ;
/* == Abstract Syntax Tree. == */

function _main() =
  (
    (
      1;
      ();
      ();
      6
    );
    ()
  )
⇒3

Example 4.21: tc -XA multiple-parse-errors.tig