Syntax
The topics are:
Script Program Syntax
A Script program is made of a sequence of
statements. Statements may include conditional statements, loops, function definitions, local variable declarations, and so forth. An
expression can also be used any time a statement is expected, in which case its value is ignored and only its side effect is taken into account. Expressions may include assignments, function calls, property access, etc.
Multiple statements or expressions may occur on a single line if they are separated by a semicolon (;). For example, the two following programs are equivalent:
Program1:
writeln("Hello, world")
x = x+1
if (x > 10) writeln("Too big")
Program2:
writeln("Hello, World"); X = X+1; If (X > 10) Writeln("Too Big")
Compound Statements
A compound statement is a sequence of statements and expressions enclosed in curly brackets ({}). It can be used to perform multiple tasks any time a single statement is expected. For example, in the following conditional statement, the three statements and expressions in curly brackets are executed when the condition a > b is true:
if (a > b) {
var c = a
a = b
b = c
}
The last statement or expression before a closing curly bracket does not need to be followed by a semicolon, even if it is on the same line. For example, the following program is syntactically correct and is equivalent to the previous one:
if (a > b) { var c = a; a = b; b = c }
Comments
Script supports two different styles of comments:
Single line comments. A single line comment starts with
// and stops at the end of the line. Example:
x = x+1 // Increment x,
y = y-1 // then decrement y.
Multiple line comments. A multiple line comment starts with a
/* and stops with a
*/; it can span multiple lines. Nested multiple line comments are not allowed. Example:
/* The following statement
increments x. */
x = x+1
/* The following statement
decrements y. */
y = y /* A comment can be inserted here */ -1
Identifier Syntax
Identifiers are used in Script to name variables and functions. An identifier starts with either a letter or an underscore, and is followed by a sequence of letters, digits, and underscores.
Here are some examples of identifiers:
car
x12
main_window
_foo
Script is case sensitive, thus the uppercase letters A-Z are distinct from the lowercase letters a-z. For example, the identifiers car and Car are distinct.
The names in the table below are reserved and cannot be used as identifiers. Some of these names are keywords used in Script; others are reserved for future use.
The names in the table below are reserved and cannot be used as identifiers. Some of these names are keywords used in Script; others are reserved for future use.
abstract boolean break byte case catch char class const continue default delete do double | else extends false final finally float for function goto if implements import in instanceof | int interface long native new null package private protected public return short static super | switch synchronized this throw throws transient true try typeof var void while with |
Published date: 05/24/2022
Last modified date: 02/24/2022