[Haskell-cafe] Writing a compiler in Hakell

S. Doaitse Swierstra doaitse at swierstra.net
Wed May 6 10:42:52 EDT 2009


Dear Rouan,

on

http://www.cs.uu.nl/wiki/HUT/WebHome

you will find a collection of tools which may help you to construct a  
compiler. As an example you will find a Tiger compiler constructed  
with the uulib tools and the uuagc attribute grammar system. Tiger is  
the language used in the book series by Andrew Apple. Not that Tiger  
is a great language, but the compiler contains an instance of all the  
things that have to be done when writing a compiler.

Once you like these tools you may take a look at the UHC compiler,  
which actually is a series of compilers, starting from a small  
language, which is than gradually extended, both with new language  
concepts and with new aspects, such as code generation, new forms of  
types etc. Here you will also see that writing a compiler for a  
language like Haskell is not a small endeavour.

You said you wanted to write a compiler in Haskell, but you did not  
say what language you want to compile? This sounds a bit strange: I  
have chosen my tool, but now I am going to decide what to use it for?

With respect to your question about the + operator. There are many  
answers to this question; but it depends on what language you are  
compiling, with which goal in mind etc. It makes a big difference  
whether you are compiling a language like Perl into some byte-code  
language which is to be interpreted in which case your aproach looks  
reasaonable, or a special purpose language describing finite state  
machines into code for an embedded system in which case your approach  
does not work out.

  Doaitse Swierstra







On 6 mei 2009, at 08:07, Rouan van Dalen wrote:

>
> Hi everyone.
>
> I am designing my own programming language.
>
> I would like to know what is the best way to go about writing my  
> compiler in haskell.
> What are the tools available in haskell that can help with compiler  
> construction?
>
> I know about Happy.  Is that a good tool to use?
>
> The compiler is intended for serious use and I would like it to be  
> very efficient, maybe competing
> with compilers written in C.  It should also be very easy to extend  
> as the languoge grows.
>
> Are there any good books that you can recommend on compiler  
> construction in general and specific to haskell?
>
>
> On another note, how is the operator + implemented in haskell?
>
> is there a primitve (say #+) that is wrapped by the haskell operator  
> +?
> Maybe something like:
>
> (+) :: a -> a -> a
> v1 + v2 = #+ v1 v2
>
>
>
>
> Thanks in advance
>
> Rouan.
>
>
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list