Tuesday, August 11, 2009

How to build a interpreter? - 1

I recently got a project to build an interpreter for RPAL. The first part of project was to build a 'scanner/lexical analyser' and then make an Abstract Syntax Tree for that. So far so good, but when I went ahead to create a scanner most of the help on the internet said that scanner is a deterministic finite automata and blah blah blah...
So, I decided to write something myself in the hope that people will find it useful. Here's a sample grammar, very small so that it doesn't inflate the post size and yet enough to show all the concept. Oh, and by the way, this will be a LL(1) parsing technique, which means we will be reading the file (which we need to scan) from left to right, and creating the tokens from left to right and we may sometimes look one character ahead to decide exactly which token to formulate.
We will also be taking care of some standard issues such as left-recursion.
In next post: The grammar

No comments: