2E Programming Language 0.9

A simple algebraic syntax language.

  Add it to your Download Basket!

 Add it to your Watch List!


Rate it!

What's new in 2E Programming Language 0.9:

  • Modified function argument separator (used to be a semicolon, now is a comma).
  • Functions are true first class values now.
  • General performance improvements.
  • Updated documentation.
Read full changelog
send us
an update
GPL (GNU General Public License) 
Derek Pressnall
ROOT \ Programming \ Code Generators
2E Programming Language (two e's, as in ee, or expression evaluator) is a simple algebraic syntax language. It natively supports expressions (composed of operators and operands), and function definitions, and basically nothing else. Therefore, it can be fairly straight-forward to learn (assuming you are already familiar with general programming constructs).

The language itself is refered to as 2e, however the interpreter is called ee.

An operand can be a literal, such as a numeric value (integer or floating point), a quoted string, a single-quoted character, a variable or a function call. Operators consist of the standard algebraic operators (i.e., *, /, +, -), assignment ("="), logical operators (, =, ==), sub-expression join operator (";"), and a conditional operator pair ("? :") like in C. Also added, is an iterative conditional pair ("?? :").

Here's a couple of examples:

ee -p '2 + 3 * 7'

In this case, when called with the "-p" flag, the next parameter is evaluated and the final result printed. The "-c" flag does the same thing, but doesn't print the final result (use this when the expression already contains output statements).

ee -c 'x = 7; y = 11; z = (x * y); print(z; "n")'

The ";" operator isn't really a statement terminator, it is actually a join operator. It evaluates the left and right expressions, and returns the result of the right hand side. It has the lowest order of precedence, so in general use you can treat it like a statement terminator (however it can be used in the middle of a larger expression, such as within parentheses grouping). It also does double-duty as a function parameter delimeter, such as the print function in the previous example.

The way that the "?" (conditoinal) operator works is as follows:

result = expr_test ? expr_true : expr_false

If expr_test is true (non-zero), then expr_true is evaluated and returned, otherwise expr_false is evaluated and returned. This is just like the inline conditional in C.

Also supported, is the iterative conditional:

result = expr_test ?? expr_true : expr_false

This will evaluate expr_test repeatedly, and as long as it is true, will evaluate expr_true. Once expr_test becomes false, then the final expr_true value is returned as the result of the whole expression. However, if expr_test never was true to begin with, then and only then is expr_false evaluated and returned. Therefore, expr_false can be used for some error handling, for example.

If an operator of lower precedence than ? or ?? is encounterd such as the ";" (join) operator, then a default false target will automatically be assumed. Therefore,

result = expr_test ? expr_true : 0; ...
result = expr_test ? expr_true; ...

are both the same. Here's a more extensive example, highlighting a few more of the operands avaliable. This example also calls the interpreter using the unix "#!" syntax, same as what is used for other scripting languages.

# This is a comment
i = 0;
x = 0;
i < 10 ?? ( # Read this as "while i is less than 10"
j = 0;
j < 5 ?? ( # while j < 5
array[i][j] = x; # here we are assigning a value to a 2-dimentional array

This example uses the iterative conditional operator to initialize an array. Notice the missing ";" after x++ and i++. this is because they are not followed by an operand (instead, in this case are followed by a closing parenthese). The ";" operator is a binary operator, no different than +, -, *, /, etc. Therefore, it is only used between to operands or two sub-expressions.

Last updated on January 13th, 2009

#programming language #algebraic syntax #syntax language #2E #programming #language #algebraic

Add your review!