Compare commits

..

No commits in common. "c4860e60b7d6e12e6dbfc402be216ec40734ba72" and "cab7424415f12be18291a967ef96f678475ef5bb" have entirely different histories.

2 changed files with 12 additions and 16 deletions

View file

@ -28,13 +28,13 @@ parseInputLine :: Int -> String -> Either ParseError Expression
parseInputLine n s = parseFullString ("stdin:" ++ show n) s parseInputLine n s = parseFullString ("stdin:" ++ show n) s
title :: [String] -> String title :: [String] -> String
title ns = " " ++ intercalate " # " ns title ns = " " ++ intercalate " | " ns
header :: [Int] -> String header :: [Int] -> String
header ws = intercalate "#" . map (flip replicate '#' . (+2) ) $ ws header ws = intercalate "|" . map (flip replicate '-' . (+2) ) $ ws
row :: [Int] -> [Bool] -> String row :: [Int] -> [Bool] -> String
row ws rs = intercalate "#" $ (zipWith row' ws rs) row ws rs = intercalate "|" $ (zipWith row' ws rs)
where where
row' :: Int -> Bool -> String row' :: Int -> Bool -> String
row' w b = replicate (left+1) ' ' ++ (if b then "1" else "0") ++ replicate (right+1) ' ' row' w b = replicate (left+1) ' ' ++ (if b then "1" else "0") ++ replicate (right+1) ' '

View file

@ -34,7 +34,7 @@ import Data.Functor.Identity
data Expression = Constant Bool | Binary BinaryOperator Expression Expression | Unary UnaryOperator Expression | Variable String data Expression = Constant Bool | Binary BinaryOperator Expression Expression | Unary UnaryOperator Expression | Variable String
deriving Show deriving Show
data BinaryOperator = LogicalAnd | LogicalOr | LogicalEquality data BinaryOperator = LogicalAnd | LogicalOr
deriving Show deriving Show
data UnaryOperator = LogicalNot data UnaryOperator = LogicalNot
deriving Show deriving Show
@ -44,9 +44,9 @@ def = emptyDef{ commentStart = ""
, commentEnd = "" , commentEnd = ""
, identStart = letter <|> char '_' , identStart = letter <|> char '_'
, identLetter = alphaNum <|> char '_' , identLetter = alphaNum <|> char '_'
, opStart = oneOf "&|~=" , opStart = oneOf "&|~"
, opLetter = oneOf "&|~=" , opLetter = oneOf "&|~"
, reservedOpNames = ["&", "|", "~", "="] , reservedOpNames = ["&", "|", "~"]
, reservedNames = ["true", "false"] , reservedNames = ["true", "false"]
} }
@ -61,9 +61,6 @@ exprparser = buildExpressionParser table term <?> "expression"
table :: [[Operator String u Identity Expression]] table :: [[Operator String u Identity Expression]]
table = [ table = [
[
Infix (m_reservedOp "=" >> return (Binary LogicalEquality)) AssocLeft
],
[ [
Prefix (m_reservedOp "~" >> return (Unary LogicalNot)) Prefix (m_reservedOp "~" >> return (Unary LogicalNot))
], ],
@ -96,5 +93,4 @@ evaluate _ (Constant b) = b
evaluate vs (Unary LogicalNot e) = not (evaluate vs e) evaluate vs (Unary LogicalNot e) = not (evaluate vs e)
evaluate vs (Binary LogicalAnd l r) = evaluate vs l && evaluate vs r evaluate vs (Binary LogicalAnd l r) = evaluate vs l && evaluate vs r
evaluate vs (Binary LogicalOr l r) = evaluate vs l || evaluate vs r evaluate vs (Binary LogicalOr l r) = evaluate vs l || evaluate vs r
evaluate vs (Binary LogicalEquality l r) = evaluate vs l == evaluate vs r
evaluate vs (Variable name) = maybe False id (Map.lookup name vs) evaluate vs (Variable name) = maybe False id (Map.lookup name vs)