[Haskell-cafe] Parse Error ( Parsec )

Mateusz Kowalczyk fuuzetsu at fuuzetsu.co.uk
Sat Jan 11 19:32:03 UTC 2014

On 11/01/14 19:12, mukesh tiwari wrote:
> Hello Cafe,
>  I am trying to write a parser for propositional logic[1]. It's working
> fine for every input except equivalence ( <=> ).
> *Main> calculator "a=>b"
> Imp (Lit 'a') (Lit 'b')
> *Main> calculator "a<=b"
> Red (Lit 'a') (Lit 'b')
> *Main> calculator "a<=>b"
> *** Exception: failed to parse
> I think, the reason is parser taking equivalence ( <=> ) as reduction ( <=
> ) and next character is '>'  so it is parse error . If I remove both
> implication and reduction then equivalence is  working fine.
> *Main> calculator "a<=>b"
> Eqi (Lit 'a') (Lit 'b')
> Could some please tell me how to solve this problem.  I also tried fixity
> declaration but got this error
> LogicPraser.hs:12:10:
>     The fixity signature for `<=>' lacks an accompanying binding
> -Mukesh Tiwari
> [1] http://logic.stanford.edu/classes/cs157/2010/notes/chap02.html
> [snip]


I have not studied your code but if the problem is what you describe
it, you should try with back-tracking so that the parser can retry
when it fails. I believe Parsec offers the ‘try’ function for this.

Regarding your ‘infix <=>’, of course that would not work. It's a
Haskell declaration, not something Parsec does.

You're getting an error because you're saying that ‘<=>’ has left fixity
of 9 but then you aren't giving a definition for ‘<=>’. The "<=>" you're
parsing has nothing to do with this. Haskell sees the fixity
declaration and then doesn't see you defining the ‘<=>’ operator
anywhere so it complains.

Mateusz K.

More information about the Haskell-Cafe mailing list