Skip to content

Files

Latest commit

dcf853b · Feb 27, 2024

History

History
96 lines (73 loc) · 2.12 KB

tutorial.adoc

File metadata and controls

96 lines (73 loc) · 2.12 KB

Syntactically, NXSL looks similar to Perl or C. Here’s simple NXSL program:

/* sample program */
function main()
{
    println("Hello!");
    return 0;
}

This program will print word Hello on screen.

Also, keep in mind that you are free to choose your own formatting style. E.g. the above could have been written as:

/* sample program */ function main(){println("Hello!");return 0;}

Now we’ll analyze this program:

/* sample program */

Everything inside /* */ is considered a comment and will be ignored by interpreter. You can enclose comments, like below:

/* comment /* another comment */ still comment */

You can also use single line comments:

x = 1; // everything between two slashes and end of line is a comment

Now onto next line:

function main()
{
}

This is a function definition. A function is a part of a program that can be called by other parts of the program. A function definition always has the following form:

function name(parameters)
{
    // the function code goes here
}

The function can return a value to the caller and accept zero or more parameters.

The function name follows the rules for all names (formally: identifiers): it must consist entirely of letters (uppercase and lowercase are different!), digits, underscores (_) and dollar signs ($), but may not begin with a digit. Please note that most special identifiers starts with dollar sign ($), so it is recommended not to start your identifiers with it.

First line in function code looks like

println("Hello!");

In this line, println is an embedded operator which prints given string to standard output with carriage return, and "Hello!" is a string we want to print. Please note semicolon at the end of line – it’s a separator between operators. Each operator should end with semicolon.

The next, and final, line of our small program is:

return 0;

return is another built-in operator which exits the function and sets it’s return value.