From 8fe1fc0c2b0b10f64c43498481e738221fe03bb3 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 12 Sep 2022 20:16:42 +0100 Subject: Track local variables, WIP code gen --- src/Micro/Parser.hs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/Micro/Parser.hs') diff --git a/src/Micro/Parser.hs b/src/Micro/Parser.hs index 89f5bc0..2ac6b13 100644 --- a/src/Micro/Parser.hs +++ b/src/Micro/Parser.hs @@ -106,7 +106,7 @@ fdef ident priv anon pos = do do x <- fStatement pure $ [x] - <|> grVar True + <|> grVar True True return $ Func ident args rtyp (concat $ body) priv anon pos function :: Bool -> Parser Expr @@ -117,26 +117,26 @@ function priv = do fdef ident priv False pos -- ident: type = value -varWithValue :: Bool -> Parser Expr -varWithValue priv = do +varWithValue :: Bool -> Bool -> Parser Expr +varWithValue local priv = do (ident, typ, _, pos) <- arg reservedOp "=" "assignation" value <- expr - return $ Var ident typ value priv pos + return $ Var ident typ value priv local pos -- group variable declaration -grVar :: Bool -> Parser [Expr] -grVar priv = do +grVar :: Bool -> Bool -> Parser [Expr] +grVar local priv = do reserved "var" - xs <- parens $ commaSep $ varWithValue priv + xs <- parens $ commaSep $ varWithValue local priv reservedOp ";" return $ xs -- variable declaration -var :: Bool -> Parser Expr -var priv = do +var :: Bool -> Bool -> Parser Expr +var local priv = do reserved "var" - x <- varWithValue priv + x <- varWithValue priv local reservedOp ";" return $ x @@ -194,12 +194,12 @@ exprStmt = do -- statements that appear in functions fStatement :: Parser Expr -fStatement = try exprStmt <|> var True <|> return' +fStatement = try exprStmt <|> var True True <|> return' -- top level statement statement :: Parser Expr statement = - try exprStmt <|> try (privateDf var) + try exprStmt <|> try (privateDf (var False)) <|> return' -- this will raise an error module' :: Parser Expr @@ -217,7 +217,7 @@ program = do do x <- try (privateDf function) <|> statement pure $ [x] - <|> privateDfn grVar + <|> privateDfn (grVar False) return $ [m] ++ (concat $ n) parse :: Parser [Expr] -- cgit v1.2.3