ScanScript
Following section describes the lexis, the syntax, and the semantics of ScanMaster™ Script.
Variables
Variables are placeholders for values. The naming conventions for the variables are as follows:
-
Names (also called identifiers) can be any string of letters, digits, and underscores, not beginning with a digit.
-
After the first character, can contain letters and numbers
-
The name cannot contain empty spaces.
The following keywords are reserved and cannot be used as names:
and | break | do | else | elseif | while |
end | false | for | function | if | in |
local | nil | not | or | repeat | return |
then | true | until | + | - | * |
/ | % | ^ | # | == | ~= |
<= | >= | < | > | = | ( |
) | [ | ] | { | } | ; |
: | , | . | .. | ... |
To use a variable in your ScanScript™, simply type an appropriate name and assign a value or string. ScanScript™ is a dynamically typed language hence the variable type depends on the value assigned to it.
The equal "=" sign is used as an assignment operator to give a value to a variable. When a variable is declared, a memory space is reserved for it. Such a space is empty until you fill it with a value.
Variable Types
All variables in ScanScript™ by default are global unless explicitly declared as local. Local variables can be defined by using the keyword local in front of the variable name.
ScanScript™ automatically converts all strings to numbers before subjecting them to an arithmetic operation and converts any numbers to strings where strings are expected.
Control Structures
Conditional statements allow you to control the flow of execution of a script or one of its sections. The conditional statements perform comparisons and act depending on the outcome of such comparisons.
if
if (condition) then
<Statements>
elseif (condition) then
<Statements>
else
<Statements>
end
while
while (condition) do
<Statements>
end
for
for index = start index, end index [,step value] do
<Statements>
end
repeat
repeat
<loop body>
until <condition>
break
The break keyword allows you to terminate a loop. This statement breaks the inner loop (for, repeat, or while) that contains it; it cannot be used outside a loop. After the break, the program continues running from the point immediately after the broken loop.
Language Operators
Relational Operators
The relational operators in ScanScript™ are:
== | Indicates whether the value of the left operand is equal to the value of the right operand. |
~= | Indicates whether the value of the left operand is not equal to the value of the right operand. |
< | Indicates whether the value of the left operand is less than the value of the right operand. |
> | Indicates whether the value of the left operand is greater than the value of the right operand. |
<= | Indicates whether the value of the left operand is less than or equal to the value of the right operand. |
>= | Indicates whether the value of the left operand is greater than or equal to the value of the right operand. |
-
These operators always result in false or true.
-
Each of these six relational operators takes two operands. These two operands must both be arithmetic or both be strings.
Arithmetic Operators
All the basic arithmetic operations can be carried out in ScanScript™. Here are the most common arithmetic operators:
+ | Addition operator (also used for String concatenation) |
- | Subtraction operator |
= | Multiplication operator |
/ | Division operator |
% | Remainder operator |
Logical Operator
Logical operators are mainly used to control the program flow. The logical operators in ScanScript™ are and, or, and not.
-
not always returns false or true
-
The conjunction operator andreturns its first argument if this value is false or nil; otherwise, and returns its second argument
Concatenation
The string concatenation operator is denoted by two dots ('..'). If both operands are strings or numbers, then they are converted to strings.
Precedence
Operator precedence in ScanScript™ follows the table below, from lower to higher priority:
or |
and |
< > <= >= ~= == |
.. |
+ - |
* / % |
not # - (unary) |
^ |
You can use parentheses to change the precedences of an expression. The concatenation ('..') and exponentiation ('^') operators are right associative. All other binary operators are left associative.
Function
C++ style function syntax supported
function FunctionName (arguments)
return (value)
end
Optional Parameters
You can specify that a method parameter is optional and no argument has to be supplied for it when the method is called. Optional parameters are indicated within square brackets [].
When you call a method with an optional parameter, you can choose whether to supply the argument.
The following syntax shows a method declaration with an optional parameter:
OpenTextFile(
string path,
FileMode mode,
[Encoding encoding]
)
The following line of code will open a text file named "readFile" in read-only mode. Note the optional parameter (Encoding.UTF8) usage:
readFile = File.OpenTextFile("Disk\\test\\txtfile.txt", FileMode.Read, Encoding.UTF8)
Nested Brackets
In some cases you will find nested brackets. These kind of brackets usually indicate dependent parameters where the immediate previous parameter becomes mandatory in order to use the subsequent optional parameter. If the subsequent parameter is not being used the immediate previous parameter will remain an optional.
For example in the following method the parameter message is mandatory and the rest are optional. However in order to use the button parameter it is required to specify a title. Likewise to use the icon parameter you must specify a button.
Smd.MessageBox(
string message,
[string title,
[Smd.MessageBoxButton button,
[Smd.MessageBoxIcon icon]]]
)