It has been a while…

A long while. Sorry. I have two excuses, a) I have a job and b) I haven’t done much programming lately.

Yesterday I have started a new project. I have been following a number of journals of late, and a number of users are making their own languages. This is an area that always fascinated me.

So my new project is such a language! Well, its not my own language – yet. At the moment I am using a syntax heavily inspired by LISP. Its been a while since I’ve used LISP, so some of the details might be different. The main reason for this is because I wanted to try my hand at writing my own parser. So far, its been pretty easy, with two notable exceptions. The first is the most pressing, error handling. Right now I have no way of reporting to the user which line a syntax error occurred on. The second is a minor one, list literals. At the moment, the parser will deep scan a list literal and find non literals inside it, whereas my intention is that it should eventually only find number, string and nested list literals inside a list literal. It shouldn’t be too hard to fix the latter, but I may have to make some larger changes to make a clean way of implementing the former.

For the moment, the actual runtime is coming along very well. I’ve gotten the following to work nicely:

-- functions!

-- types!
(print (type 32))
(print (type 'jimmy))
(print (type nil))
(print (type hello_world))

-- variables!
(global 'secret 42)
(print 'the 'secret 'is secret)

-- more variables!
(global 'foo hello_world)
(print 'foo 'is 'now 'bound 'to hello_world)
(print 'the 'type 'of 'foo 'is (type foo))
(print 'calling 'foo)
(foo) -- prints "Hello, world"

-- io!
(print 'enter 'some 'text 'please)
(print 'you 'entered (readline))

-- not implemented... yet =)
--(defun foo '(x y) '(print hello world))

At the moment I’m using lua style — comments.

Running the above script results in the following(when entering ‘ok’ when prompted):

Hello, world!
the secret is 42
foo is now bound to <LIBFUNCTION>
the type of foo is function
calling foo
Hello, world!
enter some text please
you entered ok

<LIBFUNCTION> means a function implemented in C++, rather than a native LISP function, which aren’t finished yet.

If I do say so myself, not bad for the amount of time it has taken so far. I started a similar project a couple of years ago and it did not go so well at all.

Next up (in no particular order) are control structures, proper list literals, and user defined functions. Eventually I might put a different syntax on the scripts – but for the moment I’ll see how I get on with my take on LISP…


2 Responses to “It has been a while…”

  1. Aaghaaz Madan Says:

    When you get around to functions, be sure to blog about it. 🙂

  2. bbarrett Says:

    Thats a deal!

    I have actually made some more progress, but not enough to write another entry. I’ll see how I get on tonight…

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: