Functions

A function definition has a return type, name, typed parameter list, and block body.

int add(int left, int right)
{
    return left + right;
}

Forward declarations are not supported; every function declaration must include its body.

Entry point

Programs intended for native execution define void main():

void main()
{
    print("Hello from SLangCC");
}

The semantic analyzer rejects any other return type for main and rejects explicit calls to main.

Parameters and calls

Arguments must match parameter count and types exactly:

double average(double total, double count)
{
    return total / count;
}

void main()
{
    double result = average(10.0, 4.0);
    print(result);
}

There are no default arguments, variadic user functions, or implicit argument conversions.

Call contexts

A call used as a statement must invoke a void function:

void announce(string message)
{
    print(message);
}

void main()
{
    announce("ready");
}

A call used as an expression must return a value. Discarding a non-void result or using a void call as a value is a semantic error.

Recursion

Recursive calls are supported:

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

Function names and parameter names must not be duplicated in their respective scopes. Local variables are scoped to their containing function in the current symbol-table implementation.