|
(Updated for version 0.9)
Operator Order of Precedence
Operator | Associativity | Precedence | Function |
( ) | N/A | 0 | Grouping |
{ } | N/A | 0 | Array List |
i{ } | N/A | 0 | Integer Array List |
f{ } | N/A | 0 | Float Array List |
c{ } | N/A | 0 | Character Array List |
, | N/A | 0 | Delimeter (1) |
; | Left/Right Binary | 1 | Join |
;; | Left/Right Unary | 1 | Function Return |
= | Left/Right Binary | 2 | Assignment |
: | Left/Right Binary | 3 | Conditional Else |
? | Left/Right Binary | 4 | Conditional |
?? | Left/Right Binary | 4 | Iterative Conditional |
& | Left/Right Binary | 5 | Logical AND |
|| | Left/Right Binary | 5 | Logical OR |
!= | Left/Right Binary | 6 | Comparison NOT EQUAL |
== | Left/Right Binary | 6 | Comparison EQUAL |
>= | Left/Right Binary | 6 | Comparison Greater Than or EQUAL |
<= | Left/Right Binary | 6 | Comparison Less Than or EQUAL |
> | Left/Right Binary | 6 | Comparison Greater Than |
< | Left/Right Binary | 6 | Comparison Less Than |
& | Left/Right Binary | 7 | Binary AND |
| | Left/Right Binary | 7 | Binary OR |
^ | Left/Right Binary | 7 | Binary XOR |
~ | Left/Right Unary | 7 | Binary Invert (ones compliment) |
<< | Left/Right Binary | 7 | Binary Shift Left |
>> | Left/Right Binary | 7 | Binary Shift Right |
+ | Left/Right Binary | 8 | Algebraic Add |
- | Left/Right Binary | 8 | Algebraic Subtract |
* | Left/Right Binary | 9 | Algebraic Multiply |
/ | Left/Right Binary | 9 | Algebraic Divide |
** | Right/Left Binary | 10 | Algebraic Power |
- | Right/Left Unary | 11 | Unary Negation |
++ | Right/Left Unary | 11 | Pre Increment |
-- | Right/Left Unary | 11 | Pre Decrement |
++ | Left/Right Unary | 11 | Post Increment |
-- | Left/Right Unary | 11 | Post Decrement |
[ ] | Left/Right Unary | 12 | Array Dereference (2) |
() | Left/Right Unary | 12 | Function Call |
$ | Right/Left Unary | 13 | Function Argument Dereference |
(1) The comma operator is used to delimit function arguments and array
list elements.
(2) Contents are evaluated as if they were enclosed in parentheses, and
the result is used as an index into the array. The result must be
an integer.
Built in functions
I/O functions
print(arg [; arg]...)
|
|
Takes a list of one or more arguments, and sends them to standard output one
after the other. Arguments can be of types integer, float, character, string.
No newline is printed afterwards, so you will have to specify one as an
argument if required.
|
fh = open("filename")
|
|
Opens the given filename. Takes one argument, a text string containing the
path to the file. Returns an integer which is an index to the file handle.
Otherwise, returns -1 if an error occured.
|
close(fh)
|
|
Closes the specified file handle. Takes one argument, an integer, representing
the file handle (as previously returned by open).
|
c = read(fh; count; s)
|
|
reads count number of bytes from open file fh, returns them as a string
in "s", and returns the actual number of bytes read as a result.
Takes three arguments: 1) fh is an integer, the file handle; 2) count is
an integer; s will be overwritten and re-typed as a string (if it isn't already
one). Returns an integer (bytes read).
|
c = write(fh; count; s)
|
|
writes count number of bytes to open file fh, taken from string "s", and
returns the actual number of bytes written as a result.
Takes three arguments: 1) fh is an integer, the file handle; 2) count is
an integer; 3) s is a string. Returns an integet (actual bytes written)
|
seek(fh; position)
|
|
Sets the file pointer to the given position for open file fh. Input paramets:
1) fh, an integer; 2) position, an integer
|
toeof(fh)
|
|
Sets the file pointer to end of file for open file fh. Input paramets:
1) fh, an integer
|
c = curpos(fh)
|
|
Returns the current file pointer position. Input paramets: 1) fh, an integer
Returns: position, an integer,
|
Variable manipulation functions
mkchar(v), mkint(v), mkfloat(v)
|
|
Changes the variable to a different type, preserving as much of the data as
possible. Returns the variable. Each function takes one input
parameter of type char, int, or float) and returns a character, int, or
float, respectively.
|
tochar(v), toint(v), tofloat(v)
|
|
Similar to the mk[type] functions, however they don't modify the variable
type. They just return a new value of the given type. Each function takes
one input parameter of type char, int, or float) and returns a character,
int, or float, respectively.
|
len(array)
|
|
Returns the number of elements in an array. Takes one input parameter, an
array, of any type. Since strings are character arrays, this works on
strings also. Returns an integer (count).
|
setlen(array; num)
|
|
Sets the length of an array to the givn number of elements. Takes two
parameters, "array" is an array of any type -- general purpose, character
(string), integer, float; "num" is an integer.
|
Utility and String functions
split(instring; outarray [; delimiter])
|
|
Splits the givein string into individual elements, and stores the results
in the array given by outarray. By default, the string is split on whitespace.
If a delimiter is given, then that is used as a field seperator. Takes
two to three input parameters; "instring" is a character array (string) ;
"outarray" is a general purpos array; "delimiter" is a character. The
return value is the number of elements in outarray.
|
getenv("varname")
|
|
Retrieves the given environment variable. Takes one parameter, a string,
containing the environment variable name to retrieve. Returns a string
containing the contents of that variable, or returns NULL if the variable
doesn't exist.
|
system("commandstring")
|
|
Executes the given command string, by calling the default OS shell. On Posix
systems, that is /bin/sh. Takes one parameter, "commandstring", which is a
string value containing the command along with any parameters.
|
sleep(count)
|
|
Sleeps for count number of seconds. Count can be an integer of floating
point number.
|
printf(formatstring, arg1, ...)
fprintf(file; formatstring, arg1, ...)
sprintf(outstring; formatstring, arg1, ...)
|
|
Works like the C printf function. The first parameter must be a text string
(character array). The string can contain regular text, or formatting
directives. For each formatting directive, a matching argument must also
be present. Formating directives are the same format as in the C
library printf function (i.e. %15s, or %3.2f, etc). The following
formatting functions are supported: %s for string, %d for integers,
%f for floating point values, and %c for characters.
The fprintf() function works the same way, but sends output to a file
instead. The first argument is an open file handle (as returned by the
open() function), the second is the format string. Any remaining arguments
match formatting directives. Finally, sprintf() also functions similar
to printf(), but sends output to a string instead. The first argument
of sprintf is an output string, the second argument is the format string.
|
strcpy(outstring, instring [, count])
|
|
Copies instring into outstring, replacing the contents if any. Both parameters
are string (character array) values. If outstring isn't a string, it will
be made into one. If count is specified, only count number of characters
are copied from
instring.
|
strcat(outstring, instring [, count])
|
|
Copies instring to the end of outstring.
If count is specified, only count number of characters are copied from
instring.
|
strins(outstring, instring, position [, remove_count])
|
|
Inserts instring into the string specified by outstring, starting before
the character in "position". Character count starts at zero. If remove_count
is specified, then that many characters are removed from outstring starting
at "position" prior to instring being inserted.
|
c = strcmp(str1, str2)
|
|
Compares str1 and str2. Returns -1, 0, or 1 if str1 is less than, equal to,
or greater than str2.
|
strmatch(str1, regex)
|
|
The strmatch function performs a regular expression match (giving by the string
regex) againast the string str1. Returns true (integer value 1) if a match
occures, or false (integer value 0) if no match occurs. Returns NULL if an
error occurs (which evaluates to false when refered to by conditional
operators).
|
argnames(arg1 [, arg2 ...])
|
|
The argnames function can only be used within a user defined function. It
sets each argument to an integer value representing the position that the
matching arguments were given in the calling procedure. This integer can
then be used with the "$" operand. For example:
myfunc(py, px, pz)
...
@myfunc(
n = argnames(px, py, pz);
n == 3 ? print("px is ", $px, " $py is ", py, " pz is", $pz, "\n")
)
This is useful if you want to create a function that isn't dependant on
the position of arguments that are passed to it. That way, it can be
called similiar to how you would pass arguments on a command line, such
as myfunc(px = 2 + 3, py = 7) which may suit
different programming tastes. The return result is the number of variables
that matched. If a given variable doesn't match, then it is set to NULL.
|
|