Sunday, December 27, 2009

Implement - Write a programming language in 3 hours

Yep. You read it right.
Someone told me that its impossible to implement - write a new programming language in less than a day. I said "If I can write it in python and its just has to work... Eg: no error checking or complex operation. I can write one in 3 hours".
He jumped on it VERY quickly. We agreed on all the features: "functions, global variables, local variables, addition, subtraction, print to terminal".

It has to print "Hello World", add 2+2 together and call a function which will do something.
No other restrictions. I can choose the keywords and how I represent my data types.
I did realize that it has to be very naive and super simple. I just wanted to hack something together to prove him wrong. I decided on a mixture of JavaScript and Php. I chose those two because they have a simple construct where I can easily recognize if a variable or a function getting declared or called.

Let me jump to the end of the story... I won the bet :-)
Yes, that's right. It fulfilled all the requirements we set.

In the next few blog posts I will walk you through how I hacked it together.
Stay tuned. 

Please Note!!
Don't expect a Real/True compiler or interpreter or the next big programming language!
I am NOT an expert on that field. I do love parsers/interpreters/compilers and I write simple dns(domain specific language) for work, but I am very far from understanding all the ins and outs of a language design.

No comments: