The Lambda Lab
/
projects
/
forth.jl.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
59bcf5a
)
Bootstrapping outer interpreter.
author
Tim Vaughan
<tgvaughan@gmail.com>
Mon, 4 Apr 2016 01:16:40 +0000
(13:16 +1200)
committer
Tim Vaughan
<tgvaughan@gmail.com>
Mon, 4 Apr 2016 01:16:40 +0000
(13:16 +1200)
src/forth.jl
patch
|
blob
|
history
diff --git
a/src/forth.jl
b/src/forth.jl
index
e720c7f
..
46c3c9c
100644
(file)
--- a/
src/forth.jl
+++ b/
src/forth.jl
@@
-1,23
+1,52
@@
-module
FORTH
+module
forth
-function input(prompt::AbstractString="")
- print(prompt)
- strip(readline)
+currentLine = ""
+currentPos = 0
+
+function nextLine()
+ if eof(STDIN)
+ return false
+ else
+ currentLine = readLine()
+ currentPos = 1
+ return true
+ end
+end
+
+function readPattern(pattern::Regex)
+ m = match(pattern, currentLine)
+ pos += length(m.match)
+ return m.match
end
end
-dictCore = Set{AbstractString}([
- "bye"
-])
+modes = Dict{AbstractString,Function}()
+mode = ""
-function coreEval(word::AbstractString)
- if word == "bye"
+function interpretPrimitive()
+ if haskey(dict, word)
+ dict[word]()
+ return true
+ else
+ return false
end
end
+interpretNonPrimitive() = false
+interpretNumber() = false
-function repl()
+modes["interpret"] = () -> begin
+ getWord()
+
+ if ! (interpretPrimitive() ||
+ interpretNonPrimitive() ||
+ interpretNumber())
+ println("Error: unknown word '$word'.")
+ end
+end
- while true
- line = input()
+function repl()
+ mode = "interpret"
+ while mode != "stop"
+ modes[mode]()
end
end
end
end