Parsing Haskell in Parsec

I'm trying to write a parser for a small functional language in Parsec, as part of a larger project of porting thishttp://www.cs.jhu.edu/%7Escott/pl/book/dist/from ocaml to Haskell. I was wondering if there was a parser for Haskell written in Parsec that I could use as a reference. -- Alex R

If you get the old Parsec distribution from Daan Leijen's home page there are example parsers for Henk a small functional language and I think Mondrian (a bit large one). http://legacy.cs.uu.nl/daan/parsec.html

I'm writing the parser for a Haskell-like language in Parsec
https://github.com/glutamate/baysig/blob/master/Baysig/Syntax/Parser.hs
The hand-written lexer and layout resolution code is in the same
directory. It has do-notation and custom infix declarations.
Tom
On Sun, Mar 20, 2011 at 5:25 AM, Alex Rozenshteyn
I'm trying to write a parser for a small functional language in Parsec, as part of a larger project of porting this from ocaml to Haskell.
I was wondering if there was a parser for Haskell written in Parsec that I could use as a reference.
-- Alex R
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Alex Rozenshteyn
as part of a larger project of porting http://www.cs.jhu.edu/~scott/pl/book/dist/ from ocaml to Haskell.
Nice idea. I was using a similar approach (interpreters for various semantic domains) in a course on semantics(+ compilation). I modelled it after the Turbak/Gifford book http://mitpress.mit.edu/catalog/item/?ttype=2&tid=11656 (in fact after the book had been praised in this here mailing list, about two years ago). In fact the contents of these two books seem largely similar, and the following remark holds true: Using Haskell as an implementation language, you get a very nice addition: you can model the semantics domains by Monads, and it's very natural, (Identity monad = naive interpreter, Maybe monad = for exceptions e.g. division by zero, State monad = for assignment, Continuation passing monad = for CPS style programming). Now, neither of the books dare to use the M-word. Although Turbak is really "doing monads": he is clearly defining several "bind" and "return", he's just not naming them as such. You may browse my source code (quite unpolished) here http://dfa.imn.htwk-leipzig.de/cgi-bin/gitweb.cgi?p=ws10-cb/.git;a=tree and there's a parser as well (in the Exp directory). I'd be happy to get comments on my code as well. Would it look better with Monad transformers? And there's some amount of (tree walking) boilerplate that could perhaps be replaced by some template haskell magic. But then, magic is no good in teaching... Best regards, J.W.

Thank you, everyone, for the suggestions. On Mon, Mar 21, 2011 at 12:28 PM, Johannes Waldmann < waldmann@imn.htwk-leipzig.de> wrote:
Alex Rozenshteyn
writes: as part of a larger project of porting http://www.cs.jhu.edu/~scott/pl/book/dist/ from ocaml to Haskell.
Nice idea. I was using a similar approach (interpreters for various semantic domains) in a course on semantics(+ compilation).
I modelled it after the Turbak/Gifford book http://mitpress.mit.edu/catalog/item/?ttype=2&tid=11656 (in fact after the book had been praised in this here mailing list, about two years ago).
In fact the contents of these two books seem largely similar, and the following remark holds true:
Using Haskell as an implementation language, you get a very nice addition: you can model the semantics domains by Monads, and it's very natural, (Identity monad = naive interpreter, Maybe monad = for exceptions e.g. division by zero, State monad = for assignment, Continuation passing monad = for CPS style programming).
Now, neither of the books dare to use the M-word. Although Turbak is really "doing monads": he is clearly defining several "bind" and "return", he's just not naming them as such.
You may browse my source code (quite unpolished) here http://dfa.imn.htwk-leipzig.de/cgi-bin/gitweb.cgi?p=ws10-cb/.git;a=tree and there's a parser as well (in the Exp directory).
I'd be happy to get comments on my code as well. Would it look better with Monad transformers? And there's some amount of (tree walking) boilerplate that could perhaps be replaced by some template haskell magic. But then, magic is no good in teaching...
Best regards, J.W.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Alex R

You may browse my source code (quite unpolished) ...
updated locations: http://dfa.imn.htwk-leipzig.de/cgi-bin/gitweb.cgi?p=ws10-cb.git;a=summary git clone git://dfa.imn.htwk-leipzig.de/srv/git/ws10-cb
participants (4)
-
Alex Rozenshteyn
-
Johannes Waldmann
-
Stephen Tetley
-
Tom Nielsen