Documentation

Statements

output [expression]
input [variable]
input [variable] prompt [string]
set [variable] to [expression]
if [boolean_expression] then
    [statement_1]
    . . .
    [statement_n]
endif
if [boolean_expression] then
    [statement_A1]
    . . .
    [statement_An]
else
    [statement_B1]
    . . .
    [statement_Bn]
endif
if [boolean_expression_A] then
    [statement_A1]
    . . .
    [statement_An]
elseif [boolean_expression_B] then
    [statement_B1]
    . . .
    [statement_Bn]

. . . 

else
    [statement_N1]
    . . .
    [statement_Nn]
endif
while [boolean_expression] do
    [statement_1]
    . . .
    [statement_n]
endwhile

Variables

A variable is a named area of memory that can hold one value. A variable name can be any sequence of letters {a-z, A-Z}, digits {0-9}, and the underscore {'_'}, subject to two restrictions:

Expressions

An expression can be

Examples of Expressions (using output statement)

Statement(s) What is Displayed
output "Hello World!" Hello World!
output 3 3
output 3 + 4 7
output "3 + 4" 3 + 4
output "3 + 4 = " & 3 + 4 3 + 4 = 7
set x to 7
output x * 9
63
output 2 + 3 < 4 false
output 2 < 5 and 5 < 8 true

Operators

The SPL operators are shown below, listed from highest precedence to lowest. (All operators on the same row have equal precedence.)

Operator Associativity Name/Function
( ) inner-to-outer Parentheses
^ right-to-left Exponentiation
- right Unary Minus
*, /, //, % left-to-right Multiplication, Division, Integer Division, Remainder
+, - left-to-right Addition, Subtraction
=, !=, <, <=, >, >= none Equal, Not Equal, Less Than, Less Than or Equal, Greater Than, Greater Than or Equal
not right Negation
and left-to-right Conjunction
or left-to-right Disjunction
& left-to-right String Concatenation

Associativity indicates the execution order when an expression contains multiple operators with equal precedence. For example:

Note on Integer Division (the "//" Operator)

When two numbers are divided using integer division, the result is the whole number part of the answer - i.e., the part to the left of the decimal point.

In other words, the result is truncated, not rounded.

Examples

Division Result
6 // 3 2
5 // 3 1
4 // 3 1
3 // 3 1
2 // 3 0

Useful Tip: if a < b, then a // b = 0.

Comments

The hash sign '#' indicates a comment in SPL. Anything appearing after '#' until the end of the line will be ignored.

White Space

Ordinary spaces are required to separate SPL keywords from other tokens. All other white space, while usually helpful, is optional. So, spaces are not required to separate operators from their operands, line breaks are not required to separate statements, and no indentation is required to determine scope.

For example, the following two programs are equivalent (they both display the values of 2n - 1, for n from 1 to 12):

set n to 1 
while n <= 12 do 
    output 2 ^ n - 1 
    set n to n + 1 
endwhile
                            
set n to 1 while n<=12 do output 2^n-1 set n to n+1 endwhile