Skip to content
VyJulian edited this page Mar 3, 2025 · 1 revision

SP Language Documentation

Overview

SP is a simple programming language designed for educational purposes. It supports basic programming constructs such as variables, arithmetic operations, functions, conditionals, loops, and more.

Syntax

Variables

Variables are declared and assigned using the = operator.

x = 10;
y = "Hello, World!";

Arithmetic Operations

SP supports basic arithmetic operations: addition (+), subtraction (-), multiplication (*), and division (/).

a = 5 + 3;
b = 10 - 2;
c = 4 * 2;
d = 8 / 2;

Functions

Functions are defined using the funcion keyword and can return values using the retorna keyword.

funcion suma(a, b) {
    retorna a + b;
}

resultado = suma(3, 4);  // resultado is 7

Conditionals

Conditional statements are written using si for if and alreves for else.

x = 10;
si (x > 5) {
    imprimir("x is greater than 5");
} alreves {
    imprimir("x is not greater than 5");
}

Loops

SP supports mientras (while) and para (for) loops.

Mientras Loop

i = 0;
mientras (i < 5) {
    imprimir(i);
    i = i + 1;
}

Para Loop

para (i = 0; i < 5; i = i + 1) {
    imprimir(i);
}

Print Statements

Use the imprimir function to print values to the console.

imprimir("Hello, World!");

Importing Files

Use the importar keyword to import and run another SP file.

importar("other_file.sp");

User Input

Use the entrada function to get user input.

nombre = entrada("¿Cuál es tu nombre?");
imprimir("Hola, " + nombre);

Example Program

Here is a complete example of an SP program:

funcion factorial(n) {
    si (n == 0) {
        retorna 1;
    } alreves {
        retorna n * factorial(n - 1);
    }
}

numero = 5;
resultado = factorial(numero);
imprimir("El factorial de " + numero + " es " + resultado);

This program defines a function to calculate the factorial of a number and prints the result.

License

This project is licensed under the MIT License.