diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-01-27 22:28:02 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-01-27 22:28:02 +0200 |
| commit | 2194d803b77e0384573b2b6f6217fa3c076cb92a (patch) | |
| tree | 7b2e1901619ca4bb4d63a8b54ed0d6eb8f769c6e | |
| parent | d9ecf3c4c5f3486d24c8e1d3881d075855fa5527 (diff) | |
Add line comments
| -rw-r--r-- | samples/variables.sample | 6 | ||||
| -rw-r--r-- | 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 |
