CELL – First try at a scripting language

So, before anyone jumps on the “dont make your own language” wagon, I’m only trying this because I thought it would be an interesting challange and it’d be a great oppertunity to understand how other languages work on the inside.

I’ve attempted it before, but gave up about 20 minutes in, so a few days ago I tried again. But this time I decided to go with boost spirit instead of bison, hoping that it would be easier. And it turned out it was, for me at least. So, the name! The most important part of anything! Right? So I kept thinking about some awesome names, and thought of CELL, but, so then I decided what the C, E, L, L should actually mean. So, I have an engine called Cuboid Engine, thats CE, now LL… Lightweight language! There we go! Cuboid Engine Lightweight Language, brilliant! Now I have to actually create the language.

So it’s a pretty basic setup. Using boost spirit to parse the input, compile it into tokens then do stuff with the tokens which are then translated into instructions, a list of instructions more specifically. These instructions can then be passed to the virtual machine, which works in a “stack” manner.

So it’s still pretty damn basic, but, I got a few things working:

  • Variables
  • Functions
    Arguments, Return values, Multiple Return values ( Which can be of different types )
  • Classes ( No functions yet though Posted Image )
  • External functions ( like in c++, can also be external functions from objects in c++ )
  • Local and Global Variables
    ::var <- local , local : var <- local , global : var <- global
  • If, For and While stuff
  • Logical Operators and and or
  • different assignment stuff ( += , -= *= bla bla bla )
  • And some minour stuff

Examples:

class Foo
{
    ::var = 5; // this works as a static
               // and the // is comments
};

// call external function
print("Foo value:" & ::Foo.var);
function GetAnswer()
{
    return [42];
}

function GetArrayOfAnswers()
{
    ::ans = GetAnswer();
    return [::ans,  ::ans];
}

[::ans1, ::ans2] = GetArrayOfAnswers();
print(::ans1 & ::ans2); // ouputs: 4242
function DoComputation()
{
	::comp = 412 * 0.15 + 0.85 / 43;
}

::max = 50000;
for(::i = 0; ::i < ::max; ++::i)
{
	DoComputation();
}

Yeah you get the idea… Posted Image

Hopefully I’ll get the functions implemented.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s