Language Overview

SLang is a small, statically typed, C-like teaching language. A source file uses the .sl extension and contains function definitions. Executable statements and variable declarations must be inside functions.

Complete program

int factorial(int value)
{
    if (value <= 1) {
        return 1;
    }
    return value * factorial(value - 1);
}

void main()
{
    int result = factorial(5);
    print("factorial:", result);
}

The entry point is void main(). The compiler rejects a non-void main, and main cannot be called explicitly.

Implemented features

  • six types: int, double, boolean, character, string, and void
  • initialized scalar variables and one-dimensional arrays
  • arithmetic, comparison, equality, and logical expressions
  • explicit casts between selected primitive types
  • if / elseif / else, while, and for
  • functions, parameters, return values, and recursion
  • print(...), exit(...), break, and continue
  • native x86-64 Linux executables

Important rules

SLang is intentionally stricter than C:

  • Scalar declarations require an initializer: int x = 0; is valid; int x; is not.
  • Assignment, arguments, and return values require exact type matches. There is no implicit numeric widening.
  • Function calls used as standalone statements must return void; calls used as expressions must return a value.
  • Function prototypes and global statements or variables are not supported.
  • Control-flow bodies must be brace-delimited blocks.
  • Comments begin with #, not //.

Continue with syntax, types, or the compiler quickstart.