1.6.1 How it works
Every notice from the engine is a diagnostic. They all have the same shape: a stable code, a severity, the exact position in the text and a message in the interface language. The code does not change with the language; that is why you can look it up in the catalogue.
Diagnostics are classified by when they are discovered:
| Class | When it appears | Example |
|---|---|---|
| lexical | when the text is split into pieces | a character that does not exist in the language |
| syntax | when the pieces are grouped | a missing semicolon |
| semantic | when names and types are checked | a variable nobody defined |
| runtime | while the program runs | an index outside the array |
And by severity: an error prevents the program from running; a warning points out something suspicious but lets it run; an information only informs.
Four stages in a column, lexical, syntax, semantic and runtime, each with an example on the right. A red bar next to the first three marks that they are discovered before running.
A syntax error:
ProgramThe semicolon is missing
Algorithm SinPunto
Write "hola"
EndAlgorithmDiagnostics
missingStatementTerminator· error · 2:15 · Expected a semicolon at the end of the statement
The program finishes with an error.
A semantic error:
ProgramA variable that does not exist
Algorithm SinDefinir
Write total;
EndAlgorithmDiagnostics
undeclaredVariable· error · 2:9 · Undeclared variable: total
The program finishes with an error.
A warning: the program runs anyway.
ProgramA variable too many
Algorithm SinUso
Define usada As Integer <- 3;
Define sobrante As Integer;
Write usada;
EndAlgorithmOutput
3
Diagnostics
variableDeclaredNeverUsed· warning · 3:10 · Variable declared but never used: sobrante
The program finishes normally.
A runtime failure: the analysis could not know that index 3 does not exist.
ProgramAn index outside the array
Algorithm Fuera
Dimension notas[3] As Integer;
notas[0] <- 7;
notas[1] <- 9;
notas[2] <- 6;
Write notas[3];
EndAlgorithmDiagnostics
arrayIndexOutOfRange· error · 6:9 · Index 3 is out of range for an array of size 3
The program finishes with an error.
1.6.2 No cascades
If lexical or syntax analysis finds an error, the semantic checks do not run on the broken tree. That way a single slip does not multiply into dozens of messages that explain nothing.
In short
- A diagnostic has a code, a severity, a position and a translated message.
- Classes: lexical, syntax, semantic and runtime.
- Errors prevent running; warnings do not.
- Runtime failures depend on concrete values.