Skip to main content

Your First Program

Let’s compile a simple program that demonstrates all the compiler’s capabilities. We’ll create a program that performs arithmetic and prints the result.
1

Write Your First Program

Create a file called first.txt with this content:
first.txt
let x = 5 + 3;
let y = x * 2;
print y;
This program:
  • Declares variable x and assigns it the value 8 (5 + 3)
  • Declares variable y and assigns it 16 (x * 2)
  • Prints the value of y
2

Launch the Compiler

Launch the graphical interface:
python3 compfinal.py
A window will open with:
  • Editor pane on the left for writing code
  • Output pane on the right for compilation results
  • Toolbar at the top with buttons
3

Enter Your Code

  1. Type or paste your code into the editor pane
  2. Click the Compilar button or press Ctrl+Enter
  3. Watch the output appear in the right pane
4

View the Results

The compiler will show you output from all six compilation phases:
═══════════════════════════════════════════════════════════════════════
  MINI-COMPILADOR EDUCATIVO
═══════════════════════════════════════════════════════════════════════

[FASE 1] Análisis Léxico...
         (Convirtiendo código en tokens)
  ✓ Completado: 14 tokens generados

[FASE 2] Análisis Sintáctico...
         (Verificando gramática y construyendo AST)
  ✓ Completado: AST construido con 3 sentencias

[FASE 3] Análisis Semántico...
         (Verificando lógica del programa)
  ✓ Completado: Sin errores semánticos

[FASE 4] Generación de Código Intermedio...
         (Creando representación de tres direcciones)
  ✓ Completado: 5 instrucciones IR generadas

[FASE 5] Interprete...
         (Ejecutando el programa)
  ✓ Ejecución exitosa
  Salida del programa:
  16

[FASE 6] Generación de Código Ensamblador...
         (Generando código x86)
  ✓ Completado: 87 líneas de código ASM generadas

═══════════════════════════════════════════════════════════════════════
✓ COMPILACIÓN EXITOSA
═══════════════════════════════════════════════════════════════════════

Understanding the Output

Let’s break down what each phase does with your program:
The Scanner breaks your code into tokens:
Token #1  : LET                  | Lexema: 'let'       | Línea: 1 | Col: 1
Token #2  : IDENTIFICADOR        | Lexema: 'x'         | Línea: 1 | Col: 5
Token #3  : IGUAL                | Lexema: '='         | Línea: 1 | Col: 7
Token #4  : NUMERO               | Lexema: '5'         | Línea: 1 | Col: 9
Token #5  : SUMA                 | Lexema: '+'         | Línea: 1 | Col: 11
Token #6  : NUMERO               | Lexema: '3'         | Línea: 1 | Col: 13
Token #7  : PUNTO_COMA           | Lexema: ';'         | Línea: 1 | Col: 14
...
Each piece of your code is identified and categorized.

Try More Examples

Simple Arithmetic

let result = 10 + 5 * 2;
print result;
Expected output: 20

Multiple Variables

let a = 10;
let b = 20;
let c = 30;
let sum = a + b + c;
print sum;
Expected output: 60

Parentheses

let result = (10 + 5) * 2;
print result;
Expected output: 30

Complex Expression

let x = 100;
let y = 50;
let z = (x + y) / 2;
print z;
Expected output: 75

Common First Steps

In GUI mode, your code is automatically maintained in the editor. You can manually copy it to a text file.In console mode, type your program in a text editor first, then paste it into the console.
In GUI mode, click the Export ASM button after successful compilation. Choose a location to save the .asm file.In console mode, the assembly code is printed to the console - you can redirect it to a file:
python3 compfinal.py --consola > output.txt
The compiler will show you exactly what went wrong and where:
✗ Error Sintáctico en línea 2, columna 5: Se esperaba ';' después de la expresión
Check the line and column numbers to find and fix the issue.
Yes! Export the assembly code and open it in EMU8086:
  1. Click Export ASM in the GUI
  2. Open EMU8086
  3. Load your .asm file
  4. Click Emulate to assemble and run it
  5. View the output in the EMU8086 console

Next Steps

Now that you’ve compiled your first program, dive deeper:

Language Syntax

Learn all the language features

Compiler Architecture

Understand how it works internally

More Examples

Explore complex programs

CLI Guide

Master console mode features

GUI Guide

Learn all GUI shortcuts

Understanding Output

Decode compilation results
Congratulations! You’ve successfully compiled your first program with Mini-Compilador Educativo.

Build docs developers (and LLMs) love