parse ifs

This commit is contained in:
darkf 2013-10-23 14:36:06 -07:00
parent 732802b414
commit 10d0494465
2 changed files with 11 additions and 0 deletions

1
ast.hs
View File

@ -17,6 +17,7 @@ data AST = Add AST AST
| Call String AST
| UnitConst
| Cons AST AST
| IfExpr AST AST AST
| TupleConst [AST]
| ListConst [AST]
| StrConst String

View File

@ -128,6 +128,15 @@ consExpr = do
y <- exprparser
return $ Cons x y
ifExpr = do
symbol "if"
cond <- exprparser
symbol "then"
t <- exprparser
symbol "else"
e <- exprparser
return $ IfExpr cond t e
expr' = try block
<|> try funDef
<|> try call
@ -135,6 +144,7 @@ expr' = try block
<|> try (tupleSeq exprparser TupleConst)
<|> parens exprparser
<|> listSeq exprparser ListConst
<|> try ifExpr
<|> fmap Var identifier
<|> fmap StrConst stringLiteral
<|> fmap IntConst integer