The 2E Programming Language



About
News
Getting Started
Examples
Reference

What is 2e?

The 2e language (two e's, as in ee, or expression evaluator) is an experimental algebraic syntax language. It natively supports expressions (composed of operators and operands), and function definitions. Operands are numeric literals, quoted string or (single-quoted) character values, variables, and function calls, while Operators are things like +, -, /, *, also assignment and comparison operators (>, <, ==, etc.).

Flow control (if / else, and while / do handling) is performed using special operators: the inline conditional operator pair "?" and ":" (similar to conditional operator in C), plus an iterative conditional pair "??" and ":", which is a looping version of the inline conditional operator.

Since there is very little syntax, it can be a fairly straight-forward language to learn (assuming you are already familiar with general programming constructs). The only language-specific elements you need to learn are certain operators, function definition syntax, and the included built-in functions.

Note, that the language itself is referred to as 2e, however the interpreter is called ee.

You can download the source here, or visit the Sourceforge project page.

General design philosophy of the 2e language

The 2e language is designed around evaluating expressions. An expression can be thought of as a mathematical expression, following the normal algebraic rules of operator precedence, composed of operators and operands -- for example, "2 + 5 * 7". So in a sense, 2e can be used as a simple calculator. However, expressions can contain additional operators, such as "=" (assignment), and ";" (join). These are both binary operators -- they take an operand (or sub expression) on either side. So you can have an expression such as: "a = 5; b = 7; a + b". This will create two variables, "a" and "b", assign values to them, add them, and return the result. Now the ";" operator may be thought of as a statement terminator, however it is more like the "," (comma) operator in C. So technically, in the above example, you don't have 3 separate expressions; instead you actually have one big expression.

As a fallout of everything being part of an expression composed of operands and operators, everything in 2e ends up being a first class value. For example, in C you can assign a function pointer to a variable, but in 2e you can actually include a function definition wherever you would normally use a function pointer. So in comparing a 2e implementation of qsort() with C's version, in C you have to define the comparison and swap functions somewhere else and pass pointers to them as parameters to qsort(). In 2e, you can actually define these functions right in the parameter list (see the examples page for more information).