Thursday, July 18, 2013

Why not a new programming language?



Hello World!

In the past few days I've been programming (in my spare time) a new programming language interpreter! This new interpreter is a refactored and improved version of the Ceres programming language interpreter, though the programming language syntax is not the same as before and this new interpreter is written in C whereas the other one was written in C++ and used STL. This time I'm calling the programming language Frost, first because I like cold weather, and second because the name of my previous interpreted programming language (Ceres) was the name of the goddess of agriculture and, as you might know, frosts can destroy entire crops, so a good name for a stronger successor would be one that could totally replace (or eliminate) the previous one (just like the frost over the crops).

But then you are gonna ask: why are you doing this?

One reason is because I felt that my previous interpreter was a complete failure and I wanted to create something better that could have practical uses. Another reason is because I really liked some of the characteristics of Objective-C, so I wanted to create something with some of these characteristics (named function parameters especially).

Echo, echo, echo....

Now you ask: what's special about this new programming language of yours?

Well, nothing yet. Theoretically you can write any program that you could write in C, but using my language. This language is very different from C, but it has the same basic functionalities (i.e. you can: define structs, use arrays, use control flow statements, ...), and some extra functionalities (implicit memory allocation, garbage collection through automatic reference counting, dynamically typed variables, attributes, ...). As any other major interpreted language, you can create bindings of your C functions to the interpreted program.

Example:
Here you can see a "generic" stack. This stack can receive any type of data.
In this case, it has received some matrices.

One advantage of this new programming language is that it makes it easy to define some data structures such as graphs, sets, trees, stacks, and matrices. You don't even need to specify your structure, all you need to do is create a hierarchy of arrays (you don't even need to specify the length of these arrays, though it is much more efficient if you do so). You also don't need to worry about memory allocation and deallocation, as it is done automatically for you (I still need to test it for memory leaks and "segmentation faults", but it should work well, especially if you don't have "reference loops" in your data topology).

Example:
Creating a simple binary tree...



const left = 0, right = 1;

...

main:args {

...

var root = {nil, nil}; // Root node
var childNodeLeft = {nil, nil}, childNodeRight = {nil, nil};

root[left] = childNodeLeft;
root[right] = childNodeRight;

root[left][left] = 0;
root[left][right] = 1;
root[right][left] = 2;
root[right][right] = 3;

...

}
Or, if you prefer...
var root = {{0, 1}, {2, 3}}; // Root node

You can add more levels...
var root = {{{0, 1},{2, 3}}, {{4, 5}, {6, 7}}};

Those leaf-nodes could have different types of variables...
var root = {{{'a', "Hello"},{2.5, 3}}, {{nil, {'H','E','L','L','O'}}, {-6, 7}}};

This possibility of having any type of variable in your leaf-node can be very useful because once you have programmed your own "binary-tree" library, you can use it with any type of data.

Interesting, where can I download it?

This project is available for download on SourceForge. Before downloading, note that this new language is still very young (it is almost two-weeks old) and it hasn't been properly tested nor it has some useful libraries (as of version 0.1, there is only one library: libIO that has some very simple functions for input/output).

This interpreter should compile on any POSIX system (I only used libc and posix system calls), but I only tested it on Mac OS X 10.8.4 (Darwin 12.4.0), and on Ubuntu 12.10 (Linux 3.5) and the included Makefile will only work on these systems.

Also note that I don't use efficient data structures for the internal variable and function handling (I only use linked lists), so this interpreter can run potentially slow if you have too many variables or functions in your program. I am about to improve these data structures as soon as I have time to do it...

If you plan to use this new language, note that its grammar is right-recursive (I know, it shouldn't be, but it is... I did not use Yacc to create a left-recursive grammar, I created my own recursive descent parser instead).

TL;DR

 - New interpreted programming language!
 - Interpreter written in C.
 - Structured programming language (Object-Oriented in the future)
 - Dynamically typed variables, garbage collection, attributes, named parameters, easy to create graphs and trees, ...
 - Still beta, might run slow, compiles on Linux and OS X.

Download


No comments:

Post a Comment