The 2E Programming Language



About
News
Getting Started
Examples
Reference

SourceForge.net Logo

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 refered 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 design of the 2e language had several goals. One of those goals was to see how useful it would be to have an iterative form of the C inline conditional. Once this was achieved, what would a program look like if it contained only conditional iterative conditional operators, instead of if/else and while statements? As it turns out, the code doesn't look too bad. In fact, in some instances this can lead to more succinct code, as the iterative conditional can be used in the middle of an expression, just like the regular conditional. Of course, the other issue with the iterative conditional is what to use for the operator symbol? For the time being, I've settled on using a "??", to compliment the normal conditional's "?" operator. Other character combinations I've tried tend to look to much like a weird smiley symbol, but if something better comes along I'm willing to consider it before the interpreter hits version 1.0.

Another design goal was to have a language that kept the number of special symbols to a minimum. Therefore, about the only symbols allowed are operators with the exception begin the "@" symbol that begins a function definition. Everywhere else a special symbol appears, it is either an operator, or a grouping symbol. All other advanced functionality has been pushed to functions. This will keep the programs from looking like line noise as can happen in certain other languages. The current built in function library will be expanded in future releases to include a rich variety of string handling and i/o functions. Specific categories of functions, such as screen handling or gui extentions, will be bundled with the language but will exist in loadable libraries.

Finally, I wanted a language that had a semi-traditional feel to it, but was easy to imbed. To enable 2e programs within an application, all that is required is to 1) include the appropriate headers, 2) call a setup function, 3) call a function to parse the code, 4) use some defined macros to pre-load variables that are set by the parent program (including links to functions that communicate with the parent), and finally 5) call the ee evaluator. These steps are clearly seen in the source file ee_main.c, which itself is very compact.

What's next

Documentation.
I am almost satisfied with the tutorial, however it is currently geared for existing programmers. It could stand to have a bit more focus, and some more creative code samples. Also, I need to use some more modern techniques (CSS) for the web site (the current site was thrown together rather quickly). Another area that isn't currently documented is the source code layout, how the internal data structures are defined and manipulated, and how to create additional function libraries. Some of this documentation will need to wait until there is further code cleanup, so that everything is used consistantly.

Expanded function library.
Some more text manipulation and file I/O functions are planned for the next release. Specifically, I would like to add some strong record based file routines, along the lines of some database type file operations. These will include operations to easily manipulate data in various text file formats (fixed record length, delimeted, stanza-based files, etc). Other catagories, such as interfaces with specific databases will be handled via loadable modules.

Performance improvements, language expansion.
I've already got a list of tweaks that can dramatically improve performance, however some of them may make the code a bit harder to work with. Other items will be relatively simple to add in, such as additional operators to perform bitwise and boolean operations. In addition, I am planning on adding some object oriented features to the language, specifically a limited form of operator overloading (i.e. making an operator perform differently when it is working on specific data types), which will require the ability to tag specific variables / arrays as objects. Along with this, it would be nice to introduce user-defined operators, and possibly C style structures (which will most likely be a variant of generic arrays).

If you have any questions or comments, feel free to drop me a line, dpressnall [at] gmail [dot] com, or use the forums at the sourceforge project page (http://sourceforge.net/projects/lang2e).