The Fibonacci Number: a new L+ example

I’ve just added a new example to illustrate the capabilities of the L+ language: fibo.lp

If you read our last post then, as you might recall, last Saturday we released a Free (as in Freedom) compiler called the “L+ compiler”. This program was a mandatory assignment we had to develop for a Compiler course at the Catholic University of Uruguay back in 2006.

When we introduced the compiler, we featured a simple “Hello World” program that illustrated a basic example of L+, our language. The example was very basic though, so I wanted to raise the bar and show what our little language can do.

This new program reads a number from stdin, calculates its corresponding Fibonacci number and prints the results to stdout.

The good thing about this example is that it illustrates most of L+ in action, including: I/O, function declarations, recursion, branching and string processing.

Here’s the full source code for the example. You can find it at the L+ project homepage and you also get it when you checkout the source code from Subversion.

From a compiler developer’s point of view, I can hardly tell you what it felt like seeing our compiler handling a source code as complex as this one and even catching some grammar errors every time I forgot to add a semicolon to a line.

I really encourage you to test this program, but in case you don’t, here’s the output the L+ compiler produces while compiling this program (yeah, it’s really verbose):

Finally, this is the output produced from running the program with an input value of “10”: