Skip to main content

Overview

Expresiones is a statically-typed language with three primitive data types:

int

Integer numbers

float

Floating-point numbers

bool

Boolean values

Integer Type (int)

The int type represents whole numbers without decimal points.

Declaration and Usage

// Declaration without initialization
int x;

// Declaration with initialization
int y = 10;
int valorUno = 5;
int resultado = 0;

Integer Literals

Integer literals are sequences of digits:
int a = 0;
int b = 42;
int c = 1000;
Integers can be used in arithmetic operations and comparisons.

Floating-Point Type (float)

The float type represents numbers with decimal points.

Declaration and Usage

// Declaration with decimal value
float pi = 3.14;
float area = 0.0;

Float Literals

Float literals must include a decimal point followed by digits:
float x = 3.14;
float y = 10.0;
float z = 0.5;

Float Operations

program {
    float pi = 3.14;
    int radius = 10;
    
    // Mixed arithmetic (int and float)
    float area = pi * radius;
}
Mixing int and float in operations is supported by the language grammar.

Boolean Type (bool)

The bool type represents logical true/false values.

Declaration and Usage

// Boolean declaration
bool activo = 1;  // True
bool error = 0;   // False
In Expresiones, boolean values are represented using integers: 1 for true and 0 for false.

Boolean in Conditionals

program {
    bool activo = 1;
    int x = 10;
    
    if (activo == 1) {
        x = x + 100;
    }
}

Type System

Static Typing

Expresiones requires explicit type declarations:
int x = 10;        // ✓ Correct
float pi = 3.14;   // ✓ Correct
bool flag = 1;     // ✓ Correct

// Variables must be declared before use
y = 5;             // ✗ Error: y not declared

Type Grammar

The formal grammar for types:
TIPO : 'int' | 'float' | 'bool'

Numeric Literals

Number Grammar

The grammar accepts both integer and floating-point literals:
NUMERO : [0-9]+ ('.' [0-9]+)?

Valid Number Literals

10       // Integer
42       // Integer
3.14     // Float
0.5      // Float
100.0    // Float

Invalid Literals

.5       // ✗ Must start with digit
10.      // ✗ Must have digits after decimal
3.14.15  // ✗ Only one decimal point allowed

Complete Example

program {
    // Integer variables
    int x = 10;
    int y = 5;
    int resultado = 0;
    
    // Floating-point variable
    float pi = 3.14;
    
    // Boolean variable
    bool activo = 1;
    
    // Arithmetic with different types
    resultado = x + y * 2;          // 10 + 5 * 2 = 20
    float area = pi * 10;            // 3.14 * 10 = 31.4
    
    // Boolean in conditions
    if (resultado > 15 && activo == 1) {
        x = x + 100;
    }
}

Type Usage Guidelines

Use int for:
  • Counting and indexing
  • Whole number calculations
  • Boolean-like flags (0 or 1)
  • Results that don’t need decimal precision
Use float for:
  • Scientific calculations
  • Measurements requiring decimal precision
  • Mathematical constants (like pi)
  • Division results that need precision
Use bool for:
  • Flags and state indicators
  • Condition results
  • True/false logic
  • Control flow decisions

Build docs developers (and LLMs) love