This commit is contained in:
Starfflame 2021-05-13 00:40:08 -05:00
parent 04ed7427cd
commit fe6bc4f8cb
6 changed files with 2 additions and 107 deletions

View File

@ -83,7 +83,6 @@ end
local function skipWhitespace(state: State)
local chr = state.activeInputStream:readCurrentCharacter()
while (isWhitespace(state, chr)) do
print("SKIPPING WHITESPACE")
chr = state.activeInputStream:advanceOffset()
end
end
@ -91,14 +90,10 @@ end
local function parseToken(state: State): string
local chr = state.activeInputStream:readCurrentCharacter()
local token = ""
print("paresToken called")
while(not isWhitespace(state, chr)) do
print("parsing....", chr)
token = token..chr
chr = state.activeInputStream:advanceOffset()
print(chr)
end
print("parsed", token)
return token
end

View File

@ -1,18 +0,0 @@
local WordInfo = require("WordInfo")
local type Dictionary = record
contents: {string: WordInfo}
end
function Dictionary:define(word: string, info: WordInfo)
self.contents[word] = info
end
local dict_mt = {__index = Dictionary}
function Dictionary:new(): Dictionary
return setmetatable({contents = {}} as Dictionary, dict_mt)
end
return Dictionary

View File

@ -25,23 +25,20 @@ local skipWhitespace = (CoreWords:lookup("skipWhitespace") as WordInfo).func
local parseToken = (CoreWords:lookup("parseToken") as WordInfo).func
while(true) do
print("NEW LOOP")
skipWhitespace(machineState)
local token: string = parseToken(machineState)
if isNumber(machineState, token) then
machineState.activeDataStack:push(tonumber(token))
print("ok")
else
for i, dictionary in ipairs(machineState.dictionaries) do
local wordinfo = dictionary:lookup(token)
if wordinfo then
(wordinfo as WordInfo).func(machineState)
print("ok")
goto ok
goto continue
end
end
print(string.format('%q ?', token))
::ok::
::continue::
end
end

View File

@ -1,28 +0,0 @@
local type Stack = record
contents: {any}
top: number
push: function(Stack, any)
pop: function(Stack)
new: function(Stack): Stack
end
function Stack:push(val: any)
self.top = self.top + 1
table.insert(self.contents,val)
end
function Stack:pop(): any
self.top = self.top -1
if self.top < 0 then
error("Stack underflow")
end
return table.remove(self.contents)
end
local stack_mt = {__index = Stack}
function Stack:new(): Stack
return setmetatable({contents = {}, top = 0} as Stack, stack_mt)
end
-- operations
return Stack

View File

@ -1,37 +0,0 @@
local Stack = require("Stack")
local InputStream = require("InputStream")
local Dictionary = require("Dictionary")
local type State = record
dataStacks: {Stack}
compilerStack: Stack
activeDataStack: Stack
interrupts: {function(State)}
activeInputStream: InputStream
dictionaries: {Dictionary}
end
local state_mt = {__index = State}
function State:new(): State
return setmetatable(
{
dataStacks = {},
compilerStack = Stack:new()
} as State,
state_mt)
end
function State:addDataStack(data: Stack)
table.insert(self.dataStacks, data)
end
function State:changeCompilerStack(compilerStack: Stack)
self.compilerStack = compilerStack
end
function State:changeActiveDataStack(stackIndex: number)
assert(stackIndex <= #self.dataStacks and stackIndex > 0)
self.activeDataStack = self.dataStacks[stackIndex]
end
return State

View File

@ -1,14 +0,0 @@
local State = require("State")
local type WordInfo = record
func: function(State)
immediate: boolean
end
local wordi_mt = {__index = WordInfo}
function WordInfo:new(funct: function(State), imm: boolean): WordInfo
return setmetatable({func = funct, immediate = imm} as WordInfo, wordi_mt)
end
return WordInfo