Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- log = {}
- code = [[
- a(argument,argument)
- ]]
- avoidInDef = {"?","=",";"}
- function specialchar(char)
- for i=1,#avoidInDef do
- if(char == avoidInDef[i]) then
- return false
- end
- end
- return true
- end
- function stringcheck(str)
- if(str:sub(1,1) == '"' or str:sub(1,1) == "'" and str:sub(#str,#str) == '"' or str:sub(#str,#str) == "'") then
- return true
- end
- return false
- end
- function lookupVar(variable,variables)
- for i=1,#variables do
- if(variables[i] == variable) then
- return true
- end
- end
- return false
- end
- function parse(str)
- out = {}
- variables = {}
- functions = {}
- cur = "nostate"
- secondary = ""
- third = ""
- _unknown = {}
- for i=1,#str do
- char = str:sub(i,i)
- if(cur == "nostate" and char ~= " ") then
- cur = "in-char"
- _unknown[#_unknown + 1] = char
- elseif(cur == "in-char" and specialchar(char) and char ~= " ") then
- _unknown[#_unknown + 1] = char
- end
- if(char == "=" and cur == "in-char" and char ~= " ") then
- built = ""
- for i=1,#_unknown do
- built = built.._unknown[i]
- end
- out[#out + 1] = {name = built,type = "variable",definition = ""}
- secondary = "defineVariable"
- log[#log + 1] = "Created variable "..built..", awaiting definition."
- cur = "no-state"
- third = built
- built = ""
- _unknown = {}
- elseif(char == "(" and cur == "in-char" and char ~= " ") then
- built = ""
- for i=1,#_unknown do
- built = built.._unknown[i]
- end
- print("Opening function "..built)
- cur = i
- secondary = "CloseFunction"
- third = built
- elseif(char == ")" and secondary == "CloseFunction") then
- print("Preparing to close function "..third)
- passedArgs = {}
- if(cur == i) then else
- print(str:sub(cur,i - 1))
- end
- print(stringToParse)
- elseif(specialchar(char) and secondary == "defineVariable" and char ~= " ") then
- _unknown[#_unknown + 1] = char
- elseif(not specialchar(char) and char == ";" and secondary == "defineVariable") then
- built = ""
- for i=1,#_unknown do
- built = built.._unknown[i]
- end
- for i=1,#out do
- if(out[i].type == "variable") then
- if(out[i].name == third) then
- out[i].definition = built
- end
- end
- end
- log[#log + 1] = "Defined variable "..third.." as "..built
- cur = "nostate"
- secondary = ""
- third = ""
- _unknown = {}
- end
- end
- return out
- end
- function run(parsed)
- for i=1,#parsed do
- if(parsed[i].name == "onscreen") then
- print(parsed[i].definition)
- end
- end
- end
- parse(code)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement