Skip to main content

Overview

The Mini-Compilador Educativo can be run in console mode for quick testing and batch processing. This mode accepts code input directly from the terminal and displays compilation results in real-time.

Starting Console Mode

Launch the compiler in console mode using the --consola flag:
python compfinal.py --consola
You should see:
Modo consola del mini-compilador
Escribe 'salir' para terminar. Finaliza el código con una línea vacía.

Ingresa tu código:
Console mode is ideal for quick experiments and learning the language interactively.

Writing Code in Console Mode

1

Enter your program

Type or paste your code line by line. Each statement should end with a semicolon:
let x = 10;
let y = 20;
print x + y;
2

Submit with blank line

Press Enter on an empty line to compile and execute:
The compiler will immediately process your code.
3

View results

The compiler displays all compilation phases and results:
  • Lexical analysis (tokens)
  • Syntax analysis (AST)
  • Semantic analysis
  • Intermediate representation
  • Program execution
  • Assembly generation

Example Session

Here’s a complete example of using console mode:
python compfinal.py --consola

# After prompt appears:
let a = 5;
let b = 10;
let c = a + b * 2;
print c;

# Press Enter on blank line

Command-Line Options

The compiler accepts several command-line flags:
--consola
flag
Launch in console mode instead of GUI mode

Default Behavior

When run without flags, the compiler launches the GUI:
python compfinal.py

Controlling Output Display

In console mode, all output phases are displayed by default. The GUI mode allows selective display through checkboxes.
The console mode shows:
Lists all tokens extracted from the source code:
TOKENS (resultado del análisis léxico)
════════════════════════════════════════════════════════════════
TIPO                 LEXEMA               LINEA    COLUMNA  VALOR          
────────────────────────────────────────────────────────────────
LET                  let                  1        1                       
IDENTIFICADOR        x                    1        5                       
IGUAL                =                    1        7                       
NUMERO               10                   1        9        10             
PUNTO_COMA           ;                    1        11                      
FIN_ARCHIVO                               1        12
Shows the abstract syntax tree structure:
ÁRBOL DE SINTAXIS ABSTRACTA (AST)
═══════════════════════════════════════════════════════════════
Programa
└── DeclaracionVariable
    ├── nombre: 'x'
    └── valor:
        └── NumeroLiteral(10)
Reports semantic validation results:
[FASE 3] Análisis Semántico...
         (Verificando que el código tenga sentido)
  ✓ Completado: 1 variables verificadas
Or shows errors if found:
[FASE 3] Análisis Semántico...
  ✗ Error semántico en línea 2, columna 13: la variable 'x' no ha sido declarada
Displays three-address code (TAC):
[FASE 4] Generación de Código Intermedio (IR)
         (Three Address Code)
    x = 10
    y = 20
    t0 = x + y
    print t0
Shows the program’s output:
[FASE 5] Ejecución del programa...
              (Interpretando el AST)
     Resultado:
                → 30
  ✓ Ejecución finalizada

Working with Multiple Programs

Console mode allows you to compile multiple programs in sequence:
1

Compile first program

let x = 5;
print x;

View results…
2

Compile second program

After the first compilation completes, the prompt returns:
Ingresa tu código:
Enter your next program:
let a = 10;
let b = 20;
print a + b;

3

Continue or exit

Repeat for more programs, or type salir to exit:
salir
¡Hasta luego! 👋

Handling Errors

When compilation errors occur, the compiler reports them and continues:

Lexical Errors

Ingresa tu código:
let x = @;

[FASE 1] Análisis Léxico...
  ✗ Error léxico en línea 1, columna 9: carácter inesperado '@'

Syntax Errors

Ingresa tu código:
let x 10;

[FASE 2] Análisis Sintáctico...
  ✗ Error de sintaxis en línea 1, columna 7: Se esperaba '=' después del nombre de variable. Se encontró '10'

Semantic Errors

Ingresa tu código:
let x = y + 5;

[FASE 3] Análisis Semántico...
  ✗ Error semántico en línea 1, columna 9: la variable 'y' no ha sido declarada
After an error, you can immediately enter a new program. Each compilation is independent.

Exiting Console Mode

There are three ways to exit:
At the code input prompt, type:
salir
The compiler responds:
¡Hasta luego! 👋

Tips for Effective Console Use

Prepare code externally

Write complex programs in a text editor, then paste into the console for quick testing.

Use comments

Comments (//) help document your experiments:
// Testing precedence
let x = 2 + 3 * 4;
print x;

Test incrementally

Build programs gradually, testing each addition:
let x = 10;
print x;

Then add more:
let x = 10;
let y = x * 2;
print y;

Save successful programs

Copy working programs from the terminal to save them for later reference.

Console Mode vs GUI Mode

Console Mode
Best for:
  • Quick experiments
  • Learning the language
  • Batch testing
  • Command-line workflows
  • Automated scripts
GUI Mode
Best for:
  • Writing longer programs
  • Selective output display
  • Saving and loading files
  • Exporting assembly code
  • Visual program editing

Next Steps

Using the GUI

Learn about the graphical interface for more advanced workflows

Interpreting Output

Understand what each compilation phase produces

Writing Programs

Review language syntax and best practices

Error Handling

Solve common compilation issues

Build docs developers (and LLMs) love