Skip to main content

Welcome to Expresiones

Expresiones is a complete compiler and interpreter implementation built with ANTLR4, designed to demonstrate fundamental compiler construction principles including lexical analysis, syntax parsing, semantic analysis, and expression evaluation. The language supports variable declarations with type checking, arithmetic expressions with proper operator precedence, conditional control flow, and comprehensive logical operations.

Key Features

ANTLR4 Grammar

Complete grammar definition with lexical and syntactic rules for robust language parsing

Type System

Support for int, float, and bool types with compile-time type checking

Expression Evaluation

Arithmetic expressions with correct operator precedence and parentheses support

Control Flow

Conditional statements (if-else) with relational and logical operators

Symbol Table

Complete symbol table management for tracking variable declarations and values

Visitor Pattern

Clean implementation of the visitor pattern for AST traversal and semantic analysis

Quick Example

Here’s a simple program written in the Expresiones language:
example.txt
program {
    int x = 10;
    int y = 5;
    int resultado = 0;
    
    // Arithmetic with precedence
    resultado = x + y * 2;
    
    // Conditional logic
    if (resultado > 15) {
        x = x + 100;
    } else {
        x = 0;
    }
}

How It Works

The compiler processes source code through several stages:
1

Lexical Analysis

The ExpresionesLexer tokenizes the input source code into a stream of tokens based on the grammar rules.
2

Syntax Parsing

The ExpresionesParser analyzes the token stream and builds an Abstract Syntax Tree (AST) according to the grammar’s syntactic rules.
3

Semantic Analysis

The Visitor traverses the AST, performing type checking, variable scope validation, and building the symbol table.
4

Execution

The visitor evaluates expressions and executes statements, producing output and maintaining program state.

Next Steps

Installation

Set up ANTLR4 and Python dependencies to run the compiler

Quick Start

Write and execute your first Expresiones program

Language Reference

Learn the complete syntax and semantics of the language

Architecture

Understand the compiler’s internal architecture and design

Build docs developers (and LLMs) love