Hi.

I believe I'm using parsec 3.0.1, although I already fixed the imports (even thou they were working).

Thanks for the references, specially the parsec User Guide - it saved my life, in 30 minutes I actually *understood* my mistake and fixed it. Now my code and it compiles and makes sense, even though it's a bit useless, since it has no return values [yet].

I'll take a look at UUAG and Tiger. However, since this is a simple college assignment, I want my compiler to be as simple as possible but in a way I understand what I'm doing, so I'll probably be doing it by hand.

Fernando Henrique Sanches


On Mon, Nov 30, 2009 at 2:58 PM, Stephen Tetley <stephen.tetley@gmail.com> wrote:
Hi Fernando

Which version of Parsec are you using, the one that ships with GHC or Parsec 3?

I would imagine whichever you one you are using you have the imports
wrong for these modules:

import Text.Parsec.Pos
import Text.Parsec.Prim

should be ...

import Text.ParserCombinators.Parsec.Pos
import Text.ParserCombinators.Parsec.Prim


Also it seems like an applicative instance for Parsec's GenParser
monad is missing. This isn't defined for parsec-2.1.0.1, people seem
to define it themselves:

-- The Applicative instance for every Monad looks like this.
instance Applicative (GenParser s a) where
   pure  = return
   (<*>) = ap

... you will need `ap` from Control.Monad in scope.

Also there is a pdf document for Parsec (should be available from Daan
Leijen's home page) that covers separate scanners, it has quite a lot
more documentation than Parsec's Haddock docs.

For semantic analysis I'd highly recommend UUAG, it is well documented
and used for a large compiler (EHC). There is also a version of Andrew
Appel's Tiger language written with it that is much smaller and more
comprehensible, the version on Hackage doesn't seem to contain the
attribute grammar source but it is available here:

http://www.cs.uu.nl/wiki/bin/view/HUT/TigerCompiler

http://www.cs.uu.nl/wiki/bin/view/HUT/AttributeGrammarSystem

Best wishes

Stephen