[Haskell-cafe] Parsec - separating Parsing from Lexing

Fernando Henrique Sanches fernandohsanches at gmail.com
Mon Nov 30 10:00:13 EST 2009


Hello again.

First, I'd like to thank you both for your help. You gave me nice tips and
nice material.

However, I think there is something I'm missing here. I've coded most of the
parser, and I have a feeling I'm doing some great mistake. Not only my code
won't compile, I don't know how to deal with multiple "possible return
values" and worse yet - I don't know how I'll proceed from this to Semantic
Analysis and, later, code generation. Honestly, I'm thinking I'll have to
scrap out all of this code and use the (ugh) Java template code the teacher
gave us.

My code is divided in three files:

Parser.hs (the real parsing, problematic):
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=13399#a13399

ParserTokens.hs (where I believe the problem arouse):
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=13400#a13400

Lexer.hs (the lexer, the only part I believe is mostly right):
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=13401#a13401

That's a lot of code and I feel I'm far from reaching the solution to my
problem. This code is getting ugly, and I'm somewhat desperate. Any help
will be greatly appreciated.

Fernando Henrique Sanches


On Tue, Nov 10, 2009 at 6:21 PM, Jason Dusek <jason.dusek at gmail.com> wrote:

>  You have to bootstrap your parser with something that takes
>  an `MJVal` and updates the parser state. Here is a simple
>  example:
>
>    http://github.com/jsnx/system-uuid/blob/master/Options.hs
>
>  This is a parser for command line options. It parses a list
>  of `String`s, not `Char`s (because `argv` is `char**` and not
>  `char*`, right?) so we introduce `stringPrim` and then build
>  up the primitives from that.
>
> --
> Jason Dusek
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091130/bb22f142/attachment.html


More information about the Haskell-Cafe mailing list