parse ifs
This commit is contained in:
parent
732802b414
commit
10d0494465
2 changed files with 11 additions and 0 deletions
1
ast.hs
1
ast.hs
|
@ -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
|
||||
|
|
10
parser.hs
10
parser.hs
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue