add boolean type and constants

This commit is contained in:
darkf 2013-10-23 14:41:44 -07:00
parent 10d0494465
commit 669b4a09a9
3 changed files with 6 additions and 0 deletions

1
ast.hs
View File

@ -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)

View File

@ -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

View File

@ -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