How to Write a Simple Interpreter in JavaScript
codeproject.com
codeproject.com
As for the author, it should be noted that he's a 17 year old who has been programming for 2 years. Good job - we need more people like that!
And then there are articles about building compilers which do support loops etc, but the trick is that these constructs are implemented by some other already existing machine.
So I feel like there's some gap in my education. Pointers, anybody?
Anyway, I'm pretty sure it wouldn't be that hard to extend the language to add some looping and branching constructs to the language, there's nothing really special there to add, it's just another simple type of construct to evaluate.
In my understanding, loops are implemented at the lowest level with jump instructions, but I've never really done much low-lever programming so maybe someone else can explain that better.
However modifying it to support conditionals is easy. Just add a built-in function if(condition, expr1, expr2). Now you can build if's. Since the language already properly supports recursive function calls, now it is possible to implement loops through recursion, and you're off and running.
[1] http://en.wikipedia.org/wiki/Church_encoding#Church_booleans
A two element array of function pointers (or code addresses) and an operator that turns true/false into 0/1 is enough to do conditionals.
To get an example of what can be done at the lowest level, see http://zsmith.co/intel.html for the instructions that a Pentium chip accepts. In particular look at http://zsmith.co/intel_j.html and http://zsmith.co/intel_l.html#loop.
http://compilers.iecc.com/crenshaw/
edit: BTW, https://www.coursera.org/course/compilers just started...
That being said, writing an interpreter is fun and anyone with even a mild interest in parsing or compilers should do it.
I personally enjoy using ANTLR for parsing, so that might give you a place to start.