Overview
The Mini-Compilador Educativo performs six distinct phases of compilation, each producing specific output. Understanding this output helps you learn how compilers work and debug your programs effectively.Compilation Phases
The compiler processes code through these phases:Phase 1: Lexical Analysis
Purpose
The lexer (scanner) reads source code character-by-character and groups characters into tokens - the basic building blocks of the language.Output Format
When “Mostrar tokens” is enabled, you see a table:Token Components
The category of the token:
LET,PRINT- KeywordsIDENTIFICADOR- Variable namesNUMERO- Numeric literalsSUMA,RESTA,MULTIPLICACION,DIVISION- OperatorsIGUAL- AssignmentPAREN_IZQ,PAREN_DER- ParenthesesPUNTO_COMA- Statement terminatorFIN_ARCHIVO- End marker
The actual characters from the source code.Example:
let → lexema “let”Which line of code the token appears on (1-indexed).
Character position within the line (1-indexed).
For
NUMERO tokens only: the integer value.Example: lexema “42” → valor 42Example Analysis
Common Lexical Errors
Invalid Character
Invalid Character
@, #, $)Solution: Remove or replace with valid charactersUnexpected Symbol
Unexpected Symbol
' instead of ', - instead of —)Phase 2: Syntax Analysis
Purpose
The parser verifies that tokens appear in valid grammatical order and builds an Abstract Syntax Tree (AST) representing the program’s structure.Output Format
When “Mostrar AST” is enabled, you see a tree diagram:AST Node Types
- Statements
- Expressions
DeclaracionVariableRepresents: Represents:
let x = expression;SentenciaPrintprint expression;Understanding Tree Structure
The tree structure reflects operator precedence. Deeper nodes evaluate first.
Common Syntax Errors
Missing Semicolon
Missing Semicolon
Missing Equals Sign
Missing Equals Sign
= for assignment: let x = 10;Unexpected Token
Unexpected Token
let or printUnmatched Parenthesis
Unmatched Parenthesis
let x = (10 + 5);Phase 3: Semantic Analysis
Purpose
The semantic analyzer verifies that the program is logically valid, even if syntactically correct.Checks Performed
Variable Declaration
Ensures variables are declared before use.Tracks all
let declarations and verifies identifiers exist.Division by Zero
Detects division by zero with literal values.Example:
let x = 10 / 0; is caught.Redeclaration
Warns if a variable is declared twice.Allows redeclaration but issues warning.
Output Format
Success:Common Semantic Errors
Undeclared Variable
Undeclared Variable
Division by Zero
Division by Zero
Only literal zeros are detected.
let x = 0; let y = 10 / x; won’t be caught at compile time.Variable Redeclaration (Warning)
Variable Redeclaration (Warning)
Self-Reference
Self-Reference
Phase 4: Intermediate Representation
Purpose
Converts the AST into Three-Address Code (TAC), a low-level representation where each instruction has at most three operands.Output Format
When “Mostrar IR” is enabled:Instruction Types
- Assignment
- Binary Operation
- Print
Example Transformation
Temporary variables (
t0, t1, …) represent intermediate computation results. They’re generated automatically and don’t appear in the source code.Understanding TAC
Three-address code makes operator precedence explicit:Phase 5: Program Execution
Purpose
The interpreter walks the AST and executes the program, displaying results.Output Format
How It Works
Multiple Print Outputs
Phase 6: Assembly Generation
Purpose
Produces x86 assembly code compatible with EMU8086 assembler.Assembly output is not displayed in the console/GUI output panel. Use Exportar ASM in the GUI to save to a file.
Assembly Structure
- Data Section
- Code Section
- Print Routine
dw) and newline message.Example Assembly Output
Error Message Summary
Success Indicators
Look for these messages to confirm success:Next Steps
Writing Programs
Master the language syntax to avoid errors
Error Handling
Diagnose and fix common compilation issues
Compiler Architecture
Learn how each phase is implemented
Code Generation
Understand the generated assembly code