add boolean type and constants
This commit is contained in:
parent
10d0494465
commit
669b4a09a9
3 changed files with 6 additions and 0 deletions
1
ast.hs
1
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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue