Folks,

Imagine a language where Num + Num yields a Num and Str + Num yields a Str but Num + Str should not be allowed.

I implemented parsing for such a language in OCaml with a yacc-based parser without an additional type-checking pass, entirely within the yacc grammar. I tried to take such an approach with Parsec but hit the roadblock with buildExpressionParser since it returns the same type as the token parser given to it.

Rather than have numerical expressions, string expressions, etc., as separate types, I simplified things down to a single expression type that holds my booleans, strings and numbers. I now need to implement type checking of my parsed AST.

The main issue is error reporting. I'm not sure where to get token location with Parsec and how to elegantly embed it in my AST.

Has anyone implemented type checking on top of a Parsec-based parser?

How did you locate your tokens?

        Thanks, Joel

--
http://wagerlabs.com/





_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to