Skip to content

SpecificationII · Lexical structure

2.10

Lexical errors

A lexical error appears when a piece of the text does not form any valid token: a character the language does not know, an invented escape or unclosed quotes.

Markdown version

2.10.1 How it works

Lexical analysis splits the text into pieces. If it finds something that cannot be any piece, it emits a lexical error pointing at exactly that fragment. There are three situations:

SituationDiagnostic
A character that does not belong to the language, such as @unrecognizedCharacter
An unknown escape inside a textinvalidEscapeSequence
Quotes that are never closedunterminatedString

When it can delimit the guilty fragment, the engine keeps reading to find more errors in the same pass. What it never does is invent a value or run a program with lexical errors.

Figure 2.10-1.The engine points at the guilty fragment and keeps reading. Semantic phases do not run while there are lexical errors.

A Write statement with an at sign between two texts. The at sign is marked in red and an arrow joins it to the diagnostic unrecognizedCharacter. Another arrow shows that the engine keeps reading; a dashed box recalls that no semantic analysis is done.

ProgramA character that does not exist in the language

Algorithm Arroba
  Write "correo" @ "dominio";
EndAlgorithm

Diagnostics

  • unrecognizedCharacter · error · 2:18 · Unrecognized character: @

The program finishes with an error.

There is a single diagnostic: the engine discards the @ and does not report errors caused by the gap it leaves, such as a missing semicolon.

In short

  • Three lexical errors: unknown character, invalid escape and unclosed text.
  • The diagnostic points at the exact fragment.
  • With lexical errors there is no semantic analysis or execution.