S T R U C T O R I Z E R - User Guide
Syntax > Built-in Assets

As the Executor is a Java-based interpreter, it should understand most Java commands. Besides this, it has been designed to work with basic Pascal syntax.

Reference tables

Here are the (not necessarily complete) lists of usable operators and built-in functions:

Supported Operators
Symbol Alternative symbols Description (iff = if and only if)
<- := Value assignment (including automatic variable declaration; <- displayed as in standard highlighting mode, both displayed as = in C operator mode)
+   Addition or positive sign (or string concatenation as in Java)
-   Subtraction or negative sign
*   Multiplication
/   Division (effect depends on operand types: with two integer operands, it results in an integer division)
div   Integer division (among integer operands, as in Pascal; displayed as / in C operator mode)
mod % Modulo operation among integer operands (i.e. results in the integral division remainder; displayed as % in C operator mode)
= == Comparison operator (true iff both operands are equal; displayed as == in C operator mode)
<> !=, ≠ Comparison operator (true iff both operands differ; displayed as in standard highlighting mode, as != in C operator mode)
<   Comparison operator (less than)
>   Comparison operator (greater than)
<= Comparison operator (less than or equal to; displayed as in standard highlighting mode, as <= in C operator mode)
>= Comparison operator (greater than or equal to; displayed as in standard highlighting mode, as >= in C operator mode)
and && Logical AND (true iff both Boolean operands, e.g. comparisons, evaluate to true; displayed as && in C operator mode)
or || Logical OR (true iff at least one of the two Boolean operands evaluates to true; displayed as || in C operator mode)
not ! Logical negation (true iff the Boolean operand evaluates to false; displayed as ! in C operator mode)
xor ^
Bitwise exclusive OR between integral numbers (displayed as ^ in C operator mode),
may also be used for logical XOR, but one of <>, !=, ≠ should be preferred in this case
&   Bitwise AND between integral numbers
|   Bitwise OR between integral numbers
˜   Bitwise negation of an integral number
<< shl Leftshift operator: m << n results in the integer value where all bits of integer m were shifted left by n
>> shr Rightshift operator: m shr n results in the integer value where all bits of integer m were shifted right by n
?  :   Ternary conditional expression: If the Boolean expression before the question mark is true, then the result will be the value of the expression between ? and :, otherwise the value of the expression after the colon.

Most operators are binary operators in infix notation, i.e. the operator symbol is placed between its two operands, e.g. a + 3; the operators not and ~ are unary prefix operators, i.e. they are placed before their single operand, e.g. not isDifficult, whereas the operator symbols + and - may either be binary infix (addition, concatenation, or subtraction) or unary prefix operands (sign). The conditional operator pair is ternary as it combines three expressions as operands, e.g.: text  (b > 17.3) ? "large" : "small".

Operator precedence rules (for the Executor) are similar to those of Java or C:

Operator Precedence (from highest to lowest)
Category Operators Associativity
Unary +, -, !, not, ˜
← Right to Left
Multiplicative *, /, div, %, mod
Left to Right →
Additive +, -
Left to Right →
Shift <<, shl, >>, shr
Left to Right →
Relational <, <=, ≤, >, >=, ≥
Equality =, ==, <>, !=, ≠ Left to Right →
Bitwise AND
& Left to Right →
XOR
^, xor
Left to Right →
Bitwise OR
|
Left to Right →
Logical AND
&&, and
Left to Right →
Logical OR
||, or
Left to Right →
Conditional ? :
← Right to Left
(Assignment) <-, :=

This means that e.g. logical operators like and have lower precedence than comparison operators. But be aware that this does not necessarily hold for languages like Pascal, which have much less priority levels, such that e.g. the and operator ranks like multiplication above comparison operators. Hence, an expression like

a = 3 and b < 5

may work perfectly in the Executor but will be illegal in exported Pascal code! So better use parentheses to avoid ambiguity (the code generators can hardly read your intentions):

(a = 3) and (b < 5)

Note: Incomplete and abbreviated comparisons like in

a > 2 and < 17

or

2 < a < 17

(the upper example has an incomplete comparison after the and operator, the lower "expression" would actually try to compare the Boolean result of comparison 2 < a with the numerical value 17) are illegal in Structorizer — as they are in most (but not all) high-level languages.

Like in C or Java, you may directly apply some arithmetic operators to character values, but the result will always be a numeric value: subtracting two characters will compute their code difference, but adding or subtracting an integer offset to or from a character will not result in a character but in its numerical code:

'8' - '0'    evaluates to 8 alright,
'A'
 + 17      will not result in 'R' but in 82
( it requires a built-in function to obtain the character itself:   chr('A'  + 17) ) 

Built-in Numerical Functions
Function Description
abs(x) absolute value of number x; |x|
min(x, y) minimum of numbers x and y
max(x, y) maximum of numbers x and y
round(x) nearest integral number to number x (result is of an integral type)
ceil(x) smallest integral number greater than or equal to number x (result is of a floating-point type, though)
floor(x) greatest integral number less than or equal to number x (result is of a floating-point type, though)
sgn(x) signum of number x: either -1, 0, or 1 (depending on the sign of x)
signum(x) like sgn(x) but returning a floating-point value
sqr(x) square of number x; x * x
sqrt(x) square root of number x (illegal if x is negative)
exp(x) exponential value with the Euler number e as base and x as exponent: ex
log(x) natural logarithm (i.e. based on the Euler number e) of number x; ln x; logex
pow(x, y) computes x to the power of y (where x, y, and the result are floating-point numbers): xy
cos(x) cosine of x where x is to be given in radians
sin(x) sine of x where x is to be given in radians
tan(x) tangent of x where x is to be given in radians
acos(x) arcus cosine of x (inverse cos function) where x must be between -1.0 and +1.0, the result will be in radians
asin(x) arcus sine of x (inverse sin function) where x must be between -1.0 and 1.0, the result will be in radians
atan(x) arcus tangent of x (inverse tan function), result will be in radians (as with asin, acos)
toRadians(x) converts angle x from degrees to radians
toDegrees(x) converts angle x from radians to degrees
random(n) returns an integral pseudo-random number in the range between 0 and n-1 for positive n, or between n+1 and 0 for negative n

 

Built-in Non-numerical Functions
length(s: string): int returns the number of characters the string s consists of.
length(a: array): int returns the number of elements the array a consists of.
lowercase(c: char): char

lowercase(s: string): string
returns a lower-case representation of character c

returns a string representation of string s where all letters are converted to lowercase
uppercase(c: char): char

uppercase(s: string): string
returns an upper-case representation of character c

returns a string representation of string s where all letters are converted to uppercase
pos(sub: string; s: string): int returns the first starting position of substring sub within string s (position ≥ 1 if any, otherwise 0).
copy(s: string; i: int; n: int): string returns the substring of string s that starts at character postion i (i ≥ 1) and has at most n characters
split(s: string; sep: string): array of string
split(s: string; sep: char ): array of string
breaks the string s around each occurrence of substring or character sep into pieces (some may be empty) and returns them as array
trim(s: string): string returns the trimmed string s, i.e. without leading and trailing whitespaces
strcmp(s1: string, s2: string): int returns -1, 0, or +1 if string s1 is lexicographically less than, equal to, or greater than s2, respectively
ord(c: char): int returns the ASCII code of the character c (or of the first character of string c)
chr(n: int): char returns the ASCII character coded by number n
isArray(value): bool returns true if the argument is an array
isString(value): bool returns true if the argument is a string
isNumber(value): bool returns true if the argument is an integral or floating-point number
isChar(value): bool returns true if the argument is a character
isBool(value): bool returns true if the argument is a Boolean value

 

Built-in Procedures
Procedure Description
inc(v) increments variable v by one; equivalent to: v ← v + 1
dec(v) decrements variable v by one; equivalent to: v ← v - 1
inc(v, i) increments variable v by number i; equivalent to: v ← v + i
dec(v, d) decrements variable v by number d; equivalent to: v ← v - d
randomize() is to re-initialize the pseudo number generator used for random(n)
insert(w, s, i) inserts string w at character position i into string s (i ≥ 1)
delete(s, i, n) removes the next n characters from position i out of string s (i ≥ 1)

 

File I/O

The API for working with text files was introduced on user request with release 3.26 and allows to store values as well as to produce and analyse text files with Structorizer. And of course to demonstrate the handling of resources that are controlled by the operating system.

After having opened a text file by means of one of the opening functions fileOpen, fileCreate, or fileAppend, the respective file can be accessed via the obtained "file handle" (which in fact is an integral number > 0 if the acquisition of the file was successful). Negative results of an opening attempt or 0 stand for some kind of failure and do not entitle to any kind of file access. After having worked with a successfully acquired file, on the other hand, it has to be released by means of procedure fileClose.

File API subroutines
Procedure / Function Description
fileOpen(path: string): int opens a text file for reading
(requires that the file exists),
returns a file handle (see below)
fileCreate(path: string): int creates a new file for writing
(may override an existing one),
returns a file handle (see below)
fileAppend(path: string): int opens a file for writing at end
(preserving the previus content),
returns a file handle (see below)
fileEOF(handle: int): boolean returns true if the input file is exhausted
(no more characters readable)
fileRead(handle: int): object returns the next readable data
as int or double value, flat array, or string
(see below)
fileReadChar(handle: int): char returns the next readable character (see below)
fileReadInt(handle: int): int returns the value of the next integer literal
if the next token is an integer literal
(see below)
fileReadDouble(handle: int): double returns the value of the next integer literal
if the next token is an integer literal
(see below)
fileReadLine(handle: int): string returns the (remainder of) the current line
without the newline character
(which is yet consumed, see below)
fileWrite(handle: int; value) Writes the given value to the file
without adding any separator character
fileWriteLine(handle: int; value) Writes the given value to the file
and appends a newline character
fileClose(handle: int) Closes the file identified by the handle (see below)

(Note that the "newline character" is an abstraction, which may physically be represented by a character sequence on some platforms.)

For a detailed description and several examples see File API .

Plugin subroutines

In addition to the directly built-in functions and procedures described above, Structorizer has a plugin mechanism, where so-called "Diagram Controllers" may be incorporated in. These may add more functions and procedures, which work in a similar way to built-in ones, but are only usable when the respective execution context of the plugin is activated. By now, the only such plugin is Turtleizer, however. See the respective User Guide page for details and how to enable its execution context.