Skip to content

SpecificationX · Errors and diagnostics

10.3

Recovery and order

After a syntax error, the engine looks for a safe point to keep reading: that way it reports every independent error at once, each one only once.

Markdown version

10.3.1 How it works

When a statement is badly written, analysis does not stop. It discards what it does not understand up to a synchronization point —the end of the line, a ; or the edge of a block— and continues from there. Every broken statement produces at most one main diagnostic, and errors that fall on discarded text are not reported.

ProgramTwo independent errors

Algorithm Dos
  Define a As Integer <- 1
  Write a;
  Write (a + ;
  Write "fin";
EndAlgorithm

Diagnostics

  • missingStatementTerminator · error · 2:27 · Expected a semicolon at the end of the statement
  • expectedExpression · error · 4:14 · Expected an expression

The program finishes with an error.

Figure 10.3-1.Each error discards up to the next safe point and analysis continues. Correct lines are recognised as usual.

Four lines. The first and third have an error and a mark that jumps to the next safe point; the second and fourth are recognised as usual.

A block left unclosed produces a single diagnostic, with a related span pointing to where it opens, even if other outer blocks are pending:

ProgramTwo unclosed blocks

Algorithm Abierto
  While Verdadero Do
    If Verdadero Then
      Write 1;
EndAlgorithm

Diagnostics

  • unclosedIfStatement · error · 5:1 · Unclosed if statement

The program finishes with an error.

10.3.2 Order

Diagnostics are published in a fixed order that does not depend on the language or on when they were found: first by phase (lexical, syntactic, semantic), then by position, length and code.

In short

  • After an error, analysis synchronizes and continues.
  • A broken statement gives at most one main diagnostic.
  • An unclosed block gives a single diagnostic.
  • The order is fixed: phase, position, length and code.