BASIC Developer & Support Resources > Interpreters


(1/2) > >>

I guess this is not basic related, but this is the only fun forum there is for these kind of things so ... :)

I made a quick experiment with writing an interpreter for a new language in naalaa a while ago ( This resultet in a language that was way more "powerful" than naalaa itself. So I decided to rewrite it in C, and this is the result so far. At a first glance it may look like Lua but with C-like syntax, but ... it's not.

I'm not quite sure where I'm heading with this, but I've attached the sourcecode, you can build it with the makefile (on Linux). Sorry again about this not really being basic related.

There are some example programs included. Here's one about functions:

--- Code: ---/*
 * File: functions.txt
 * -------------------

/* Functions are assigned to variables using function. */
helloWorld = function() {
    wln("Hello world!");

/* Call helloWorld. */

/* Create a new function that takes two parameters and returns their sum. */
sum = function(a, b) {
    return a + b;
wln(tostring(sum(3, 7)));

/* When calling a function, two reference variables are always created: this
   and self. self can be used for object-based design and is explained in
   another example. this is a reference to the function variable itself. */
countDown = function(n) {
    if (n > 1) {
        /* Make a recursive call through this. Actually we couldn't call
           countDown for this purpose here, because functions can't normally
           access variables from the main program. */
        this(n - 1);

/* If the function variable has sub-variables you can access those through
   this. */
name.first = "John";
name.last = "Doe";
name = function() {
    return this.first + " " + this.last;

--- End code ---

One of the weirdest things with the language, compared to Lua and Javascript, is that a variable can have an intrinsic value and sub-variables at the same time. You can see that in the last part of the code above. The variable 'name' has two sub-variables (first and last), while its intrinsic value is a function that returns the two sub-variables combined.

I called the language prolan earlier, but now it's JAIL (just another interpreted language). I like stupid names.


The make worked fine on my Ubuntu 64 bit laptop.

I would of never have imagined creating an interpreter in NaaLaa but I've learned to not to underestimate your creative energy.

The latest version can be found here:

The thing I posted earlier was filled with bugs.

Hmmmmm .... interesting .... *scratches chin*

I can see this evolving into something quite useful.

Right now, I'm assuming that it is an interpreter only.

How fast is it (running either as naalaa or as C)?
How strongly typed are the variables?
What's it like handling strings (the big problem area with C IMHO)

I like the sub-variables - a good place to put such properties as ~.length, ~.type, and so on (but not to the ridiculous extent as with Python and Java) - subpended functions are a pain!

I look forward to seeing the next stage.

BTW - are you planning on porting SICK to JAIL?  :o

It's a pure interpreter (no bytecode step), so it's slow as hell, haha :)

It's dynamically typed. The variable types are number, string and function. A variable may also reference another variable, but it's more like creating aliases. Strings work ... fine :)

There's no coercion at all.


[0] Message Index

[#] Next page

Go to full version