[Haskell-beginners] A Pascal-like Language Compiler

Joel Björnson joel.bjornson at gmail.com
Mon Oct 20 09:47:44 EDT 2008

Oops, should have hit the replay-to-all button, so sorry Pranesh for
double posting.

have you considered using BNCF[1]? With BNFC you can define a grammar
for your language then let the BNFC converter generate a Haskell
parser (along with an ADT representing syntax trees).

On Mon, Oct 20, 2008 at 2:09 PM, Pranesh Srinivasan <spranesh at gmail.com> wrote:
> 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 ?)

I think it is probably better to exclude  the variable look up, type
checking etc from the parsing phase. Here's an example of a general

1. Parse input file into an abstract syntax tree representation.
2. Perform type checking on your syntax tree.
3. Transform the syntax tree using re-write rules and optimisations.
4. Pretty print the syntax tree in order to output code of your target language.

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

I would say probably easier then in many other languages since Haskell
has such a great support for recursive data types, pattern matching

>    * how would one go about implementing basic error recovery in the
>      parser (make it skip the current line, or block) ?
Not really sure what you mean by error recovery but when using BNFC
all of the tedious work of implementing the parsers is automated.

[1] http://www.cs.chalmers.se/Cs/Research/Language-technology/BNFC/

More information about the Beginners mailing list