-
Notifications
You must be signed in to change notification settings - Fork 1
/
SequentParseMonad.hs
51 lines (42 loc) · 1.35 KB
/
SequentParseMonad.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module SequentParseMonad where
import Haskelle
import Monad
import ParseMonad
data SeqExpr = Expr :|-: Expr
data Expr = Con String | Expr :&: Expr | Expr :|: Expr | Expr :->: Expr deriving (Eq, Show)
evalExpr :: Expr -> Proposition
evalExpr (Con s) = Atomic s
evalExpr (e :&: f) = Conjunction (evalExpr e) (evalExpr f)
evalExpr (e :|: f) = Disjunction (evalExpr e) (evalExpr f)
evalExpr (e :->: f) = Implication (evalExpr e) (evalExpr f)
evalSeqExpr :: SeqExpr -> Sequent
evalSeqExpr ((Con " ") :|-: post) = (Sequent [] [evalExpr post])
evalSeqExpr (pre :|-: post) = (Sequent [evalExpr pre] [evalExpr post])
seqexpr :: Parser SeqExpr
seqexpr = parseNoAssumption `mplus` parseAssumption
where
parseAssumption = do { a <- expr; token '|'; token '-'; b <- expr; return (a :|-: b) }
parseNoAssumption = do { token '|'; token '-'; b <- expr; return ((Con " ") :|-: b) }
expr :: Parser Expr
expr = parseCon `mplus` parseConj `mplus` parseDisj `mplus` parseImpl
where
parseCon = do { s <- parseStr; return (Con s) }
parseConj = do { token '(';
d <- expr;
token '&';
e <- expr;
token ')';
return (d :&: e) }
parseDisj = do { token '(';
d <- expr;
token '|';
e <- expr;
token ')';
return (d :|: e) }
parseImpl = do { token '(';
d <- expr;
token '-';
token '>';
e <- expr;
token ')';
return (d :->: e) }