From 2194d803b77e0384573b2b6f6217fa3c076cb92a Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Thu, 27 Jan 2022 22:28:02 +0200 Subject: Add line comments --- src/main.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main.hs b/src/main.hs index fc5d60c..cfa5f65 100644 --- a/src/main.hs +++ b/src/main.hs @@ -41,11 +41,14 @@ interpretWord ((LVariable a) : b : stack) dict word@(LSymbol "!") = in pure (stack, newDict) interpretWord ((LVariable a) : stack) dict word@(LSymbol "@") = let lookupWord = dict ! a - newDict = M.delete a dict - in pure (lookupWord : stack, newDict) + in pure (lookupWord : stack, dict) interpretWord (a : stack) dict word@(LSymbol ".") = do putStrLn $ reprWord a pure (stack, dict) +interpretWord ((LVariable a) : stack) dict word@(LSymbol "?") = do + let lookupWord = dict ! a + putStrLn $ reprWord lookupWord + pure (stack, dict) -- math interpretWord ((LInteger a) : (LInteger b) : stack) dict word@(LSymbol "+") = pure $ (LInteger (a + b) : stack, dict) -- error @@ -58,7 +61,8 @@ main = do putStrLn $ "[info] executing file " ++ filename source <- readFile filename putStrLn source - let parsed = parseSource source + let sourceWoComments = source $> lines .> filter (\line -> not ("--" `isPrefixOf` line)) .> unlines + let parsed = parseSource sourceWoComments putStrLn $ "[info] parsed words:\n" ++ show parsed putStrLn "[info] interpreter output:" interpretSource [] M.empty parsed -- cgit v1.3