summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2022-01-27 22:28:02 +0200
committerJan Tuomi <jans.tuomi@gmail.com>2022-01-27 22:28:02 +0200
commit2194d803b77e0384573b2b6f6217fa3c076cb92a (patch)
tree7b2e1901619ca4bb4d63a8b54ed0d6eb8f769c6e /src
parentd9ecf3c4c5f3486d24c8e1d3881d075855fa5527 (diff)
Add line comments
Diffstat (limited to 'src')
-rw-r--r--src/main.hs10
1 files changed, 7 insertions, 3 deletions
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