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

Web page: https://pseudolearn.app/en/spec/lexico/errores

> **In one sentence**
>
> 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.

## 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:

| Situation | Diagnostic |
| --- | --- |
| A character that does not belong to the language, such as `@` | `unrecognizedCharacter` |
| An unknown escape inside a text | `invalidEscapeSequence` |
| Quotes that are never closed | `unterminatedString` |

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: A lexical error and recovery**

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.

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

### Program: A character that does not exist in the language

```pseudolearn
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.

> **Limit**
>
> Analysis accepts up to 256 constructs nested at once: parentheses, argument and index lists, unary operators, chained powers, each link of a chain of calls or member accesses and compound statements inside others. The next one produces `analysisNestingLimitExceeded`. The limit protects the engine; no reasonable program gets close to it.

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

**See also**
- [2.7 Text and character literals](https://pseudolearn.app/en/spec/lexico/textos.md)
- [10.2 Severity and classes](https://pseudolearn.app/en/spec/diagnosticos/severidad.md)
