Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A programming language written in naalaa
#1
Sorry for being quiet for a while.

I decided I wanted to experiment with writing an interpreter for a programming language in naalaa, just for fun. It quickly got out of control and is now a mix of C, naalaa and LUA. You can easily do OOP style programming in it.

I will rewrite and develop this further in C and see if something useful pops out. But if you want to have a look at the naalaa code, I've attached it to this post. There are a couple of example programs included in a folder named "tests". Open prolan.nala/prolan.txt in NED and modify a line at the beginning of the source code to change which program to run:

Code:
    ' Change this to functions.txt, loops.txt, oop.txt, variables2.txt or
    ' variables.txt.
    FILENAME$    "variables.txt"

Here's one of the example programs that demonstrates OOP-style programming:

Code:
Person = function(firstName, lastName, age) {
    p.firstName = firstName;
    p.lastName = lastName;
    p.age = age;

    p.setFirstName = function(name) {
        self.firstName = name;
    };

    p.setLastName = function(name) {
        self.lastName = name;
    };

    p.setAge = function(age) {
        self.age = age;
    };

    p.getFirstName = function() {
        return self.firstName;
    };

    p.getLastName = function() {
        return self.lastName;
    };

    p.getName = function() {
        return self.firstName + " " + self.lastName;
    };

    p.getAge = function() {
        return self.age;
    };

    p.tostring = function() {
        return self.getName() + " (" + tostring(self.age) + ")";
    };

    return alias(p);
};

ListPersons = function(alias list) {
    for (p: list) {
        wln(p.tostring());
    }
};

ListPersonsUsingGlobal = function() {
    for (p: persons) {
        wln(p.tostring());
    }
};

wln("Creating 4 identical persons");
for (i = 1, 4) {
    persons[i] == Person("John", "Doe", 40);
}
ListPersons(persons);
wln("");

wln("Changing two of them");
persons[1].setFirstName("Marcus");
persons[1].setLastName("Johansson");
persons[1].setAge(39);

p = alias(persons[2]);
p.setFirstName("Frank");
p.setLastName("Foulbottom");
p.setAge(56);
unalias(p);

visible persons;
ListPersonsUsingGlobal();

I'm a bit amazed I could make this work as a naalaa program, haha Smile


Attached Files
.zip   prolan.zip (Size: 20.77 KB / Downloads: 20)
Reply
#2
Seems to work OK.

 Just a little bit above my skill level, but you might just have something there.
Reply
#3
Thumbs Up 
I am also impressed. It looks to be a very elegant language. Perhaps one could use the .sbe file of the interpreter to implement a scripting environment for their NaaLaa game (though I would find that delightfully ironic)...
Reply
#4
(06-14-2018, 01:33 AM)X54321 Wrote: I am also impressed. It looks to be a very elegant language. Perhaps one could use the .sbe file of the interpreter to implement a scripting environment for their NaaLaa game (though I would find that delightfully ironic)...

Of course, then some clever wossname will write an interpreter in the scripting language inside the game ....
Reply
#5
(06-14-2018, 08:32 AM)AlyssonR Wrote:
(06-14-2018, 01:33 AM)X54321 Wrote: I am also impressed. It looks to be a very elegant language. Perhaps one could use the .sbe file of the interpreter to implement a scripting environment for their NaaLaa game (though I would find that delightfully ironic)...

Of course, then some clever wossname will write an interpreter in the scripting language inside the game ....

mind = blown;
Reply
#6
Hello Marcus:

     This new compiler reminds me about what I recently seen on YouTube. Someone made a channel about learning how to make a new programing language. He  had a good idea, but his code was too hard to read, and his compiler was too slow.

     The reason I think YouTube would be a good place for this is it contains a good method for freezing the screen, which allows you to study the code. Space bar freezes the screen and brings it back. The "k" key does the same thing. The "j" key goes back several frames and "l" goes forward several frames.
Reply
#7
(06-15-2018, 01:29 PM)Rick3137 Wrote: Hello Marcus:

     This new compiler reminds me about what I recently seen on YouTube. Someone made a channel about learning how to make a new programing language. He  had a good idea, but his code was too hard to read, and his compiler was too slow.

     The reason I think YouTube would be a good place for this is it contains a good method for freezing the screen, which allows you to study the code. Space bar freezes the screen and brings it back. The "k" key does the same thing. The "j" key goes back several frames and "l" goes forward several frames.

Thanks for the idea, but compiler/interpreter construction isn't something that I'm good at. I even dropped out of a Compiler Construction course at the university because I couldn't understand a word of what he professor was talking about.

Anyone who knows about this stuff would laugh at and point out flaws in what I'm doing. And that goes for naalaa too. There are probably better tutorials and examples available on the web.

A big flaw in the interpreter I posted here is of course the memory management. All variables are handled as keys, and every time a variable is accessed the interpreter goes searching in a big array for its key. This will be handled with hash tables or trees in the C version. It will still be a pure interpreter though, probably as slow as Python, haha.
Reply
#8
It's no longer naalaa-related, but it might still be of interest to some.

This interpreter is currently what I'm working on at my spare time. I've spent many hours on rewriting it in C, and now it has all the functionality of the naalaa version.  I've attached the sourcecode and a bunch of examples, you can build it with the makefile (I've only tried it on Linux, but with the right tools installed it should work on Windows too).

It needs a system for writing and importing libraries and an easy way to communicate with C functions. It may become a standalone language or something that you just embed in other C programs, I'll see what happens.


Attached Files
.gz   prolan.tar.gz (Size: 26.62 KB / Downloads: 4)
Reply
#9
Yo Marcus
How is possible that i don't know about this ?
And i find it on JRS AllBasic site Smile 
May I publish this interpreter on my forum too?
Already there are good amount of experimental langs..

Also you say ..not in NaaLaa than in C , why not in Naalaa?
Is it slow or what?

all best
Aurel Smile
Reply
#10
You can find the latest version of the interpreter here:

http://jail.naalaa.com/

There were lots of bugs in the early thing I posted at allbasic.info. Now thing function as they should, and I've started working on some standard libraries. Extending the interpreter with C functions is pretty easy, and most of the libraries have their C counterpart (the string.txt library calls functions in pl_string.c and so on).

It's Linux only so far, but maybe it's possible to build it on Windows through MinGW? When I have a Windows machine again, I'll probably make it work with Visual Studio.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)