The 2E Programming Language



About
News
Getting Started
Examples
Reference

(Updated for version 0.9)

Operator Order of Precedence

OperatorAssociativityPrecedenceFunction
( )N/A0Grouping
{ }N/A0Array List
i{ }N/A0Integer Array List
f{ }N/A0Float Array List
c{ }N/A0Character Array List
,N/A0Delimeter (1)
;Left/Right Binary1Join
;;Left/Right Unary1Function Return
=Left/Right Binary2Assignment
:Left/Right Binary3Conditional Else
?Left/Right Binary4Conditional
??Left/Right Binary4Iterative Conditional
&Left/Right Binary5Logical AND
||Left/Right Binary5Logical OR
!=Left/Right Binary6Comparison NOT EQUAL
==Left/Right Binary6Comparison EQUAL
>=Left/Right Binary6Comparison Greater Than or EQUAL
<=Left/Right Binary6Comparison Less Than or EQUAL
>Left/Right Binary6Comparison Greater Than
<Left/Right Binary6Comparison Less Than
&Left/Right Binary7Binary AND
|Left/Right Binary7Binary OR
^Left/Right Binary7Binary XOR
~Left/Right Unary7Binary Invert (ones compliment)
<<Left/Right Binary7Binary Shift Left
>>Left/Right Binary7Binary Shift Right
+Left/Right Binary8Algebraic Add
-Left/Right Binary8Algebraic Subtract
*Left/Right Binary9Algebraic Multiply
/Left/Right Binary9Algebraic Divide
**Right/Left Binary10Algebraic Power
-Right/Left Unary11Unary Negation
++Right/Left Unary11Pre Increment
--Right/Left Unary11Pre Decrement
++Left/Right Unary11Post Increment
--Left/Right Unary11Post Decrement
[ ]Left/Right Unary12Array Dereference (2)
()Left/Right Unary12Function Call
$Right/Left Unary13Function 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.