Skip to main content

What is Mini-Compilador Educativo?

Mini-Compilador Educativo is a fully functional educational compiler designed to teach the fundamental concepts of compiler construction. Built for the Compiler course at ESIME Culhuacán (Group 5CM24), it provides a complete implementation of all major compilation phases from lexical analysis through code generation.
Authors: Fidel Ruiz Diego and Sánchez Flores Luis Leonardo
Professor: Veloz Ortiz Efren
Institution: ESIME Culhuacán

Why This Compiler?

Complete Pipeline

Implements all six phases of compilation: lexical, syntactic, semantic analysis, IR generation, interpretation, and code generation

Educational Focus

Extensively commented code with clear explanations makes it perfect for learning compiler design

Real Assembly Output

Generates actual x86 assembly code compatible with EMU8086 emulator

Dual Interfaces

Both CLI and GUI modes with syntax highlighting and live compilation

What Problems Does It Solve?

Traditional compiler courses often struggle with:
  • Abstract concepts: Compiler theory can be difficult to grasp without seeing it in action
  • Large codebases: Production compilers are too complex for educational purposes
  • Limited feedback: Students need to see each compilation phase’s output
  • Setup complexity: Many compiler tools require complex build environments
This compiler solves these problems by:
  • Providing clear, visible output at each compilation stage
  • Keeping the codebase manageable (~2100 lines of well-documented Python)
  • Including both text-based and visual representations of data structures
  • Running with just Python 3.x - no complex setup required

Key Capabilities

Lexical Analysis (Scanner)

Converts source code into a stream of tokens:
# Source code
let x = 5 + 3;

# Tokens generated
[LET, IDENTIFICADOR(x), IGUAL, NUMERO(5), SUMA, NUMERO(3), PUNTO_COMA]

Syntactic Analysis (Parser)

Builds an Abstract Syntax Tree (AST) from tokens:
DeclaracionVariable
├── nombre: "x"
└── expresion: ExpresionBinaria
    ├── izquierda: NumeroLiteral(5)
    ├── operador: +
    └── derecha: NumeroLiteral(3)

Semantic Analysis

Validates logical correctness:
  • Checks for undefined variables
  • Detects potential division by zero
  • Warns about variable redeclaration
  • Identifies self-referential assignments

Intermediate Representation

Generates three-address code (TAC):
t1 = 5 + 3
x = t1

Interpreter

Executes programs directly without assembly:
Programa ejecutado correctamente.

Code Generation

Produces x86 assembly for EMU8086:
.model small
.stack 100h
.data
    x dw 0
.code
main proc
    mov ax, @data
    mov ds, ax
    
    ; x = 5 + 3
    mov ax, 5
    push ax
    mov ax, 3
    mov bx, ax
    pop ax
    add ax, bx
    mov x, ax
    
    mov ah, 4Ch
    int 21h
main endp
end main

Who Should Use This?

Perfect for students taking compiler design courses who want to understand how compilers work by examining real, working code.
Provides a complete, teachable compiler implementation that can be used in lectures, labs, and assignments.
Anyone interested in compiler construction can study this codebase to learn the fundamental techniques.
Developers interested in creating their own programming languages can use this as a reference implementation.

The Compiler Workflow

1

Write Source Code

Create a program using the simple imperative language syntax with let and print statements
2

Lexical Analysis

The Scanner reads your code character by character and groups them into tokens
3

Syntactic Analysis

The Parser validates token order against the grammar and builds an AST
4

Semantic Analysis

The Semantic Analyzer checks for logical errors like undefined variables
5

IR Generation

The IR Generator creates three-address code for optimization opportunities
6

Interpretation (Optional)

The Interpreter can execute your program directly to verify correctness
7

Code Generation

The Assembly Generator produces x86 code that can run on EMU8086

Quick Example

Here’s a complete program and its compilation:
let a = 10;
let b = 20;
let sum = a + b;
print sum;

Next Steps

Installation

Set up Python and install the compiler

Quick Start

Compile your first program in minutes

Architecture

Understand how the compiler is structured

API Reference

Explore the compiler’s classes and methods