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 )
- 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 functionprint("Foo value:" & ::Foo.var);
function GetAnswer(){ return [42];}function GetArrayOfAnswers(){ ::ans = GetAnswer(); return [::ans, ::ans];}[::ans1, ::ans2] = GetArrayOfAnswers();print(::ans1 & ::ans2); // ouputs: 4242
[code=:0]function DoComputation(){ ::comp = 412 * 0.15 + 0.85 / 43;}::max = 50000;for(::i = 0; ::i < ::max; ++::i){ DoComputation();} Yeah you get the idea...
Hopefully I'll get the functions implemented.