Question

I'm using Parsec and the example version of boolExpr http://hpaste.org/86299 at the moment. I'm compiling on Windows via GHC.

The code above will match a boolean expression like 3 < 4 or a not 3 however it will not match an expression like 3, true or (((3 < 1))). Can anyone give me advice on how to match such expressions like 3 and (((3 < 1))) the same as 3 > 0 and (((3 < 1))) > 0, where the >0 is assumed/added automatically on RHS-less expressions?

Was it helpful?

Solution

This looks like you're trying to push the semantics of your language into a syntax parser. The "correct" thing to do from a programming-languages perspective is to accept both number and boolean-valued expressions in your syntax tree. Then, at a later stage -- type reconstruction not parsing -- decide that number-valued expressions get a single "> 0" added to them while boolean valued expressions do not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top