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";
EndAlgorithmDiagnostics
missingStatementTerminator· error · 2:27 · Expected a semicolon at the end of the statementexpectedExpression· error · 4:14 · Expected an expression
The program finishes with an error.
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;
EndAlgorithmDiagnostics
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.