
Hi Mateusz,
Thank you. Now it's working fine by using 'try' function.
-Mukesh Tiwari
On Sun, Jan 12, 2014 at 1:02 AM, Mateusz Kowalczyk
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]
Hi,
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. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe