parse: refactored block parsing; all: added while loops

This commit is contained in:
2017-05-19 13:35:32 +02:00
parent 6a651bbf1a
commit ca11f51e33
3 changed files with 45 additions and 14 deletions

View File

@@ -6,18 +6,22 @@ data Value = BNum Number
| BBool Bool
| BSym String
| BIf [Value] [Value] (Maybe [Value])
| BWhile [Value] [Value]
| BDef Value [Value]
| BErr String
instance Show Value where
show (BBool b) = if b then "true" else "false"
show (BDef sym expr) = show sym ++ " = " ++ unwords (map show expr)
show (BIf x y z) =
"if (" ++ unwords (map show x) ++ ") {\n\t" ++
intercalate "\n\t" (map show y) ++ "\n}" ++
(case z of
show (BIf cond body alt) =
"if (" ++ unwords (map show cond) ++ ") {\n\t" ++
intercalate "\n\t" (map show body) ++ "\n}" ++
(case alt of
Just vals ->
" else {\n\t" ++ intercalate "\n\t" (map show vals) ++ "\n}"
Nothing -> "")
show (BWhile cond body) =
"while (" ++ unwords (map show cond) ++ ") {\n\t" ++
intercalate "\n\t" (map show body) ++ "\n}"
show (BSym o) = o
show (BNum n) = show n
show (BErr e) = "error: " ++ e