Your First Program
Let’s create and compile a simple Expresiones program that demonstrates variable declarations, arithmetic operations, and conditional logic.Create a Program File
Create a new file called
programa.txt with the following content:Every Expresiones program must start with the
program keyword followed by a block enclosed in curly braces.Run the Compiler
Navigate to your source directory and run the compiler:A file dialog will open. Select your
programa.txt file.Understanding the Output
The Expresiones compiler provides two types of output:Execution Trace
As the compiler processes your code, it prints execution information:- Declaración: Shows when a variable is declared with its type and initial value
- Asignación: Shows when a variable is assigned a new value
Symbol Table
The final symbol table displays:- ID: Variable name
- Tipo: Variable type (
int,float, orbool) - Valor: Final value after execution (or
Noneif never assigned)
Advanced Example
Here’s a more complex example demonstrating all language features:This example is from
entrada.txt in the source repository and demonstrates:- Variable declarations with initialization
- Arithmetic operations with correct precedence
- Logical operators (
&&,||,!) - Nested conditionals
- Parentheses for expression grouping
- Mixed integer and floating-point arithmetic
Language Features
Data Types
Expresiones supports three data types:Operators
Arithmetic:+, -, *, /
Relational: >, <, ==, != (or <>), >=, <=
Logical: && (and), || (or), ! (not)
Control Flow
Conditional statements with optional else clause:Comments
Single-line comments start with//:
Common Patterns
Variable Declaration
Complex Conditions
Arithmetic Expressions
Next Steps
Explore the Grammar
Learn about the complete grammar definition in
Expresiones.gVisitor Pattern
Understand how the Visitor pattern is used to traverse the AST
Language Reference
Dive into the complete language syntax and semantics
Examples
Explore more code examples and patterns
Running Without GUI
If you want to run the compiler without the file dialog (useful for automation), you can modifyPrueba.py:16-18: