diff options
author | Juan J. Martinez <jjm@usebox.net> | 2022-09-01 22:34:28 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2022-09-01 22:34:38 +0100 |
commit | 3d2b80cf454e682ba1fcd094465b7ee1a94297dd (patch) | |
tree | 68b6731494756df20fc4cc0cea3b556f92f0ed12 /src/Parser.hs | |
parent | 476b0d2d6c27b9ec326b465480795582a3b22f4c (diff) | |
download | micro-lang-hs-3d2b80cf454e682ba1fcd094465b7ee1a94297dd.tar.gz micro-lang-hs-3d2b80cf454e682ba1fcd094465b7ee1a94297dd.zip |
Variable declaration
Diffstat (limited to 'src/Parser.hs')
-rw-r--r-- | src/Parser.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Parser.hs b/src/Parser.hs index ea698c8..f341bc2 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -43,7 +43,7 @@ variable :: Parser Expr variable = do pos <- getPosition var <- identifier - return $ Var var pos + return $ Variable var pos typ :: Parser Type typ = do @@ -116,6 +116,16 @@ call = do args <- parens $ commaSep expr return $ Call ident args pos +var :: Parser Expr +var = do + pos <- getPosition + reserved "var" + (ident, typ, _) <- arg + reservedOp "=" <?> "assignation" + value <- expr + reservedOp ";" + return $ Var ident typ value pos + factor :: Parser Expr factor = number @@ -150,7 +160,7 @@ program = do n <- many $ do function - -- TODO: variable decl + <|> var <|> statement <?> "statement" return $ [m] ++ n |