Commit d113d25f authored by AVANZINI Martin's avatar AVANZINI Martin
Browse files

bExp parser accepts parens

parent 6173cd3f
{-# OPTIONS_GHC -fno-warn-incomplete-patterns #-}
{-# LANGUAGE DeriveTraversable, PatternSynonyms, StandaloneDeriving #-}
{-# LANGUAGE DeriveTraversable, PatternSynonyms, TypeSynonymInstances, StandaloneDeriving #-}
module Data.PWhile.BoolExpression
(
Conj (..)
......
......@@ -194,16 +194,6 @@ normFromBExp :: BExp -> NormTemplate
normFromBExp b = sum [ normFromExp (e1 - e2 + 1)
| e1 :>=: e2 <- S.toList (literals b) ]
-- normFromCExp :: C.CExp Rational -> NormTemplate
-- normFromCExp d = sum [ normFromBExp b + norm n
-- | C.GNorm b k n <- varGNorms d
-- , k > 0, not (C.isZeroN n) ]
-- guardNormsFromCExp :: C.CExp Rational -> NormTemplate
-- guardNormsFromCExp d = sum [ normFromBExp d
-- | C.GNorm b k n <- varGNorms d
-- , k > 0, not (C.isZeroN n) ]
substituteM :: (C.Norm -> SolveM NormTemplate) -> NormTemplate -> SolveM NormTemplate
substituteM s = P.fromPolynomialM s (pure . P.coefficient)
......@@ -246,7 +236,7 @@ boundedSum (i,f) (l,o) = bs f
PP.<+> PP.pretty i
PP.<+> PP.text "<="
PP.<+> PP.pretty o))
t <- template "guarded" (pure (sum [ nn * ng
t <- template "guarded" (pure (sum [ nn * nn + nn * ng
| C.GNorm b _ n <- varGNorms g
, let nn = norm n
, let ng = sum [ normFromExp (e1 - e2 + 1)
......
......@@ -96,17 +96,17 @@ withIndent cmb pHead pBody = L.indentBlock whitespaceN p where
pBExp :: Parser BExp
pBExp = makeExprParser bTerm bOperators where
bTerm = do
e1 <- pAExp
op
<- ((.<=) <$ symbol "<=")
<|> ((.>=) <$ symbol "=>")
<|> ((.>=) <$ symbol ">=")
<|> ((.<) <$ symbol "<")
<|> ((.>) <$ symbol ">")
<|> ((.==) <$ symbol "=")
e2 <- pAExp
return $ e1 `op` e2
bTerm =
try (parens pBExp)
<|> ( do e1 <- pAExp
op <- ((.<=) <$ symbol "<=")
<|> ((.>=) <$ symbol "=>")
<|> ((.>=) <$ symbol ">=")
<|> ((.<) <$ symbol "<")
<|> ((.>) <$ symbol ">")
<|> ((.==) <$ symbol "=")
e2 <- pAExp
return $ e1 `op` e2 )
bOperators =
[ [ Prefix (neg <$ keyword "not") ]
, [ InfixL ((.&&) <$ keyword "and")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment