From 669b4a09a942815c74199aab57fb57489fcb2c2c Mon Sep 17 00:00:00 2001 From: darkf Date: Wed, 23 Oct 2013 14:41:44 -0700 Subject: [PATCH] add boolean type and constants --- ast.hs | 1 + interp.hs | 2 ++ parser.hs | 3 +++ 3 files changed, 6 insertions(+) diff --git a/ast.hs b/ast.hs index 7476849..573cfb6 100644 --- a/ast.hs +++ b/ast.hs @@ -20,6 +20,7 @@ data AST = Add AST AST | IfExpr AST AST AST | TupleConst [AST] | ListConst [AST] + | BoolConst Bool | StrConst String | IntConst Integer deriving (Show, Eq) diff --git a/interp.hs b/interp.hs index c57f23d..344e556 100644 --- a/interp.hs +++ b/interp.hs @@ -21,6 +21,7 @@ instance Eq BIF where a == b = False data Value = IntV Integer | StrV String | UnitV + | BoolV Bool | StreamV Int | TupleV [Value] | ListV [Value] @@ -99,6 +100,7 @@ eval :: AST -> InterpState Value eval (IntConst i) = return $ IntV i eval (StrConst s) = return $ StrV s +eval (BoolConst b) = return $ BoolV b eval UnitConst = return UnitV diff --git a/parser.hs b/parser.hs index d2613f1..6a9345b 100644 --- a/parser.hs +++ b/parser.hs @@ -137,6 +137,8 @@ ifExpr = do e <- exprparser return $ IfExpr cond t e +bool = fmap BoolConst $ (symbol "true" >> return True) <|> (symbol "false" >> return False) + expr' = try block <|> try funDef <|> try call @@ -145,6 +147,7 @@ expr' = try block <|> parens exprparser <|> listSeq exprparser ListConst <|> try ifExpr + <|> bool <|> fmap Var identifier <|> fmap StrConst stringLiteral <|> fmap IntConst integer