[Haskell-beginners] A Pascal-like Language Compiler

Pranesh Srinivasan spranesh at gmail.com
Mon Oct 20 08:09:50 EDT 2008

Hi all,

I have been learning haskell for the last month or so. I have just
started becoming familiar with monads and looking at Parsec.

As part of the Language Translators Course this semester, in the
university I study, we are to implement a Pascal-like toy language to C
translator[1]. The aim is to take a simple subset of Pascal and
translate it to an intermediate 3 operand format, before translating it
to simple C.

The time I have for this project is about a month. I am contemplating
doing this in Haskell, since I have read in several places that Haskell
(and other functional languages) is very good for writing compilers. In
fact, I have started writing code for lexing the basic tokens.

I do have doubts about my ability to finish it. The curiosity to do
something of a moderate size in Haskell, and the extremely friendly
folks on #haskell, tipped me on this decision.

I looked around for similar things on the internet, in vain. I have
several doubts at this stage some of which include,

    * how the parser will determine the scope of the variables,
      i.e, how can a symbol table be implemented (in the state of the
      parser ?)

    * how easy or difficult will basic code optimisation (like unused
      variables, and loops with no side effects) and type checking be?

    * how would one go about implementing basic error recovery in the
      parser (make it skip the current line, or block) ?

I would love it if I get a few pointers from people who have been there,
done that.

Or am I being too ambitious too early? :)

[1] One of the suggested programming exercises at the end of the
"Dragon" Compilers book, by Aho, et al.

Pranesh S

More information about the Beginners mailing list