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 --- samples/variables.sample | 6 ++++++ src/main.hs | 10 +++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/samples/variables.sample b/samples/variables.sample index 43d798c..5ea1105 100644 --- a/samples/variables.sample +++ b/samples/variables.sample @@ -1,2 +1,8 @@ +-- store foo = 10 10 $foo ! + +-- load and print foo +$foo ? + +-- print 1 + value at foo 1 $foo @ + . 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