Modified conditions and started to implement If statements
This commit is contained in:
parent
4669f33760
commit
15c738d597
@ -4,6 +4,7 @@ local Stack = require("dms.stack")
|
|||||||
local Chunk = require("dms.chunk")
|
local Chunk = require("dms.chunk")
|
||||||
local Cmd = require("dms.cmd")
|
local Cmd = require("dms.cmd")
|
||||||
local Value = require("dms.value")
|
local Value = require("dms.value")
|
||||||
|
local Queue = require("dms.queue")
|
||||||
local ENTR,ENAB,DISA,LOAD,VERN,USIN,STAT,DISP,ASGN,LABL,CHOI,OPTN,FORE,UNWN,WHLE,FNWR,FNNR,IFFF,ELIF,ELSE,DEFN,SKIP,COMP,INDX,JMPZ = "ENTR","ENAB","DISA","LOAD","VERN","USIN","STAT","DISP","ASGN","LABL","CHOI","OPTN","FORE","????","WHLE","FNWR","FNNR","IFFF","ELIF","ELSE","DEFN","SKIP","COMP","INDX","JMPZ"
|
local ENTR,ENAB,DISA,LOAD,VERN,USIN,STAT,DISP,ASGN,LABL,CHOI,OPTN,FORE,UNWN,WHLE,FNWR,FNNR,IFFF,ELIF,ELSE,DEFN,SKIP,COMP,INDX,JMPZ = "ENTR","ENAB","DISA","LOAD","VERN","USIN","STAT","DISP","ASGN","LABL","CHOI","OPTN","FORE","????","WHLE","FNWR","FNNR","IFFF","ELIF","ELSE","DEFN","SKIP","COMP","INDX","JMPZ"
|
||||||
local controls = {STAT,CHOI,FORE,WHLE,IFFF,ELIF,ELSE}
|
local controls = {STAT,CHOI,FORE,WHLE,IFFF,ELIF,ELSE}
|
||||||
local flags = {ENTR,ENAB,DISA,LOAD,VERN,USIN,DEFN}
|
local flags = {ENTR,ENAB,DISA,LOAD,VERN,USIN,DEFN}
|
||||||
@ -14,6 +15,9 @@ local recognizedFlags = {
|
|||||||
}
|
}
|
||||||
local parser = {}
|
local parser = {}
|
||||||
parser.__index = parser
|
parser.__index = parser
|
||||||
|
local iStack = Stack:new()
|
||||||
|
local fStack = Stack:new()
|
||||||
|
local wStack = Stack:new()
|
||||||
function parser:new(path)
|
function parser:new(path)
|
||||||
local c = {}
|
local c = {}
|
||||||
setmetatable(c,self)
|
setmetatable(c,self)
|
||||||
@ -333,12 +337,12 @@ function parser:parse()
|
|||||||
groupStack:append{line_num,group,IFFF,self.filename,line:trim()}
|
groupStack:append{line_num,group,IFFF,self.filename,line:trim()}
|
||||||
elseif line:match("else%s*(.+)") then
|
elseif line:match("else%s*(.+)") then
|
||||||
groupStack:append{line_num,group,ELSE,self.filename,line:trim()}
|
groupStack:append{line_num,group,ELSE,self.filename,line:trim()}
|
||||||
elseif line:match("[%s,%$_%w]*=(.+)") then
|
|
||||||
groupStack:append{line_num,group,ASGN,self.filename,line:trim()}
|
|
||||||
elseif line:match("[%l_][%w_]-%(.+%)") then
|
elseif line:match("[%l_][%w_]-%(.+%)") then
|
||||||
groupStack:append{line_num,group,FNNR,self.filename,line:trim()}
|
groupStack:append{line_num,group,FNNR,self.filename,line:trim()}
|
||||||
elseif line:match("\"(.+)\"") then
|
elseif line:match("\"(.+)\"") and not line:match("=.-\".-\"") then
|
||||||
groupStack:append{line_num,group,DISP,self.filename,line:trim()}
|
groupStack:append{line_num,group,DISP,self.filename,line:trim()}
|
||||||
|
elseif line:match("[%s,%$_%w]-=(.+)") then
|
||||||
|
groupStack:append{line_num,group,ASGN,self.filename,line:trim()}
|
||||||
else
|
else
|
||||||
groupStack:append{line_num,group,UNWN,self.filename,line:trim()}
|
groupStack:append{line_num,group,UNWN,self.filename,line:trim()}
|
||||||
end
|
end
|
||||||
@ -403,9 +407,21 @@ function parser:parse()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
local EQ,GTE,LTE,NEQ,GT,LT = "=",char(242),char(243),char(247),">","<"
|
local EQ,GTE,LTE,NEQ,GT,LT = "=",char(242),char(243),char(247),">","<"
|
||||||
|
function parser:JMPZ(v,label)
|
||||||
|
local cmd = Cmd:new({self.current_lineStats[1],0,JMPZ,self.current_lineStats[2],"?"},JMPZ,{label = label,var = v})
|
||||||
|
function cmd:tostring()
|
||||||
|
return self.args.var .. ", " ..self.args.label
|
||||||
|
end
|
||||||
|
self.current_chunk:addCmd(cmd)
|
||||||
|
end
|
||||||
function parser:parseIFFF(line)
|
function parser:parseIFFF(line)
|
||||||
|
line[5] = self:logicChop(line[5])
|
||||||
print(line[5])
|
print(line[5])
|
||||||
print(self:logicChop(line[5]))
|
local v = self:parseExpr(line[5])
|
||||||
|
local labelE = gen("$labelEnd_")
|
||||||
|
self:JMPZ(v,labelE)
|
||||||
|
iStack:push({cmds = Queue:new()})
|
||||||
|
io.read()
|
||||||
end
|
end
|
||||||
function parser:buildLogic(l,o,r,v)
|
function parser:buildLogic(l,o,r,v)
|
||||||
local cmd = Cmd:new({self.current_lineStats[1],0,COMP,self.current_lineStats[2],"?"},COMP,{left=l,op=o,right=r,var=v})
|
local cmd = Cmd:new({self.current_lineStats[1],0,COMP,self.current_lineStats[2],"?"},COMP,{left=l,op=o,right=r,var=v})
|
||||||
@ -699,7 +715,7 @@ function parser:parseChoice(line)
|
|||||||
local choice = {text = text,options = {}}
|
local choice = {text = text,options = {}}
|
||||||
local cmd = Cmd:new(line,CHOI,choice)
|
local cmd = Cmd:new(line,CHOI,choice)
|
||||||
function cmd:tostring()
|
function cmd:tostring()
|
||||||
return "\""..self.args.text.."\" {"..table.concat(self.args.options,", ").."}"-- disp choices
|
return "\""..self.args.text.."\", "..table.concat(self.args.options,", ")-- disp choices
|
||||||
end
|
end
|
||||||
self.current_chunk:addCmd(cmd)
|
self.current_chunk:addCmd(cmd)
|
||||||
if copt[3]~=OPTN then
|
if copt[3]~=OPTN then
|
||||||
|
|||||||
27
dms/queue.lua
Normal file
27
dms/queue.lua
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
local Queue = {}
|
||||||
|
Queue.__index = Queue
|
||||||
|
function Queue:__call()
|
||||||
|
local function next()
|
||||||
|
return self:dequeue()
|
||||||
|
end
|
||||||
|
return next
|
||||||
|
end
|
||||||
|
function Queue:__tostring()
|
||||||
|
return table.concat(self.queue, ", ")
|
||||||
|
end
|
||||||
|
function Queue:new()
|
||||||
|
local c = {}
|
||||||
|
setmetatable(c,self)
|
||||||
|
c.queue = {}
|
||||||
|
return c
|
||||||
|
end
|
||||||
|
function Queue:enqueue(data)
|
||||||
|
table.insert(self.queue,data)
|
||||||
|
end
|
||||||
|
function Queue:peek(data)
|
||||||
|
return self.queue[1]
|
||||||
|
end
|
||||||
|
function Queue:dequeue(data)
|
||||||
|
return table.remove(self.queue,1)
|
||||||
|
end
|
||||||
|
return Queue
|
||||||
18
test.lua
18
test.lua
@ -1,11 +1,9 @@
|
|||||||
package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path
|
package.path="?.lua;?/init.lua;?.lua;?/?/init.lua;"..package.path
|
||||||
require("dms.utils")
|
local queue = require("dms.queue"):new()
|
||||||
--require("dms.parser")
|
queue:enqueue(1)
|
||||||
parser = {}
|
queue:enqueue(2)
|
||||||
|
queue:enqueue(3)
|
||||||
|
queue:enqueue(4)
|
||||||
print(parser:logicChop([[if (func(123)!=name[1] or true == "Bob") and foodCount >= 10.34]]))
|
for i in queue() do
|
||||||
-- function parser:parseLogic(expr)
|
print(i)
|
||||||
-- expr = expr:gsub("")
|
end
|
||||||
-- end
|
|
||||||
-- print(parser:parseLogic([[if (name=="Ryan" or name == "Bob") and foodCount >= 10]]))
|
|
||||||
Loading…
x
Reference in New Issue
Block a user