Skip to content

SpecificationI · Overview

1.6

Errors, warnings and failures

The engine warns with diagnostics: errors prevent running, warnings do not, and failures happen while the program runs.

Markdown version

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:

ClassWhen it appearsExample
lexicalwhen the text is split into piecesa character that does not exist in the language
syntaxwhen the pieces are groupeda missing semicolon
semanticwhen names and types are checkeda variable nobody defined
runtimewhile the program runsan 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.

Figure 1.6-1.The diagnostic classes along the journey of the program. The first three are discovered before running.

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"
EndAlgorithm

Diagnostics

  • 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;
EndAlgorithm

Diagnostics

  • 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;
EndAlgorithm

Output

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];
EndAlgorithm

Diagnostics

  • 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.