The compiler detects and reports errors at three different phases: lexical analysis, syntax analysis, and semantic analysis. This page demonstrates common errors and how they are caught.
Detected during tokenization. These errors occur when the scanner encounters invalid characters or malformed tokens.Examples: @, #, $, or other characters not in the language.
Phase 2: Syntax Errors
Detected during parsing. These errors occur when tokens are in the wrong order or structure.Examples: missing semicolons, mismatched parentheses, wrong keyword order.
Phase 3: Semantic Errors
Detected during semantic analysis. These errors occur when code is syntactically correct but logically invalid.Examples: undefined variables, division by zero.
let x = 10;let @invalid = 5; // '@' is not validprint x;
[FASE 1] Análisis Léxico... (Convirtiendo código en tokens) ✗ Error léxico en línea 2, columna 5: carácter inesperado '@' ✓ Completado: 11 tokens generados[FASE 2] Análisis Sintáctico... (Verificando gramática y construyendo AST) ✗ Error de sintaxis en línea 2, columna 5: Se esperaba nombre de variable después de 'let'. Se encontró ''[FASE 3] Análisis Semántico... (Verificando que el código tenga sentido) ⚠ Omitido debido a errores de sintaxis ✗ RESULTADO: 2 error(es) encontrado(s)
The lexer detects the invalid character @ at line 2, column 5
It creates an ERROR token for this character
The parser then fails because it expected an identifier after let
[FASE 1] Análisis Léxico... (Convirtiendo código en tokens) ✓ Completado: 7 tokens generados[FASE 2] Análisis Sintáctico... (Verificando gramática y construyendo AST) ✗ Error de sintaxis en línea 1, columna 7: Se esperaba '=' después del nombre de variable. Se encontró '10' ✓ Completado: 1 sentencias parseadas[FASE 3] Análisis Semántico... (Verificando que el código tenga sentido) ⚠ Omitido debido a errores de sintaxis ✗ RESULTADO: 1 error(es) encontrado(s)
Lexical analysis succeeds (all characters are valid)
Parser expects = after the variable name x
Instead, it finds the number 10
Clear error message shows exactly what was expected and what was found
let x = x + 1; // 'x' used in its own definitionprint x;
Error:
[FASE 3] Análisis Semántico... ✗ Error semántico en línea 1, columna 9: la variable 'x' no ha sido declarada
Variables cannot reference themselves in their own declaration. The variable is only added to the symbol table after its initialization expression is analyzed.
Error semántico en línea 3, columna 9: la variable 'count' no ha sido declarada│ │ │ │ ││ │ │ │ └─ Description│ │ │ └────────────────── Column number│ │ └────────────────────────────── Line number│ └──────────────────────────────────────── "at line"└─────────────────────────────────────────────────────── Error type
Use the line and column numbers to quickly locate errors in your source code. Most text editors can jump to a specific line:column position.