Simply used to parse a simple programming language I call BBPL.
I’m not done yet, not a lot to do.
EX:
Msg("Blahblahblah")
randomfunction(1+2+3+4+5)
Variable = 10+5/5
Create bbpl/TEST.txt then c&p this code.
Lua should be placed in autorun.
Type in runfile and watch it parse the code in the console.
No real instructions, this is not a real release of anything.
[lua]bbpl = {}
bbpl.Data = {}
function bbpl:DoString(str)
Msg(string.byte(“A”)…" “…string.byte(“a”)…” “…string.byte(“Z”)…” “…string.byte(“z”)…” “…string.byte(“1”)…” “…string.byte(“9”)…”
“)
local str = string.Replace(str,”
“,”
“)
local lines = string.Explode(”",str)
local chunk = “”
local Ret = false
local FunctionPar = 0
local CurFunc = “”
local CurVar = “”
local DeclareChunk = “”
local DeclareVar = “”
local InOperation = false
local InQuotes = false
local InDeclare = false
local Args = {}
for k,v in pairs(lines) do
if v == “”" then
if InQuotes then
InQuotes = false
else
InQuotes = true
end
end
if (v == "
“) and !InQuotes and !InDeclare then
Ret = true
end
if v == “(” and !InQuotes then
if InDeclare then
InDeclare = false
DeclareChunk = chunk
DeclareVar = CurVar
local newchunk = string.Explode(” “,string.Trim(string.Replace(chunk,”
“,” “)))
chunk = newchunk[#newchunk]
end
FunctionPar = FunctionPar + 1
if FunctionPar == 1 then
Ret = true
CurFunc = string.Trim(chunk)
chunk = “”
end
elseif v == “)” and !InQuotes then
if FunctionPar == 1 then
table.insert(Args,chunk)
//local args = string.Explode(”,",chunk)
for k,v in ipairs(Args) do
Args[k] = bbpl:Operations(v)
end
bbpl:DoFunction(CurFunc,Args)
Msg("Run Function: “…CurFunc…”
“)
Msg(“Arguments: “…string.Implode(”,”,Args)…”
“)
chunk = “”
Args = {}
Ret = true
else
//Msg(“ERROR!: Unnecessary ‘)’”)
end
FunctionPar = FunctionPar - 1
else
if FunctionPar then
if v == “,” and !InQuotes then
table.insert(Args,chunk)
Ret = true
chunk = “”
end
end
end
if v == “=” and !InQuotes then
if InDeclare then
DeclareChunk = chunk
DeclareVar = CurVar
local newchunk = string.Explode(” “,string.Trim(string.Replace(chunk,”
“,” “)))
CurVar = newchunk[#newchunk]
else
CurVar = string.Trim(chunk)
InDeclare = true
//bbpl.Data[chunk]
end
chunk = “”
Ret = true
end
if k == #lines then
if InDeclare then
DeclareChunk = chunk…v
DeclareVar = CurVar
end
end
if string.len(DeclareChunk) > 0 then
local newchunk = string.Explode(” “,string.Trim(string.Replace(DeclareChunk,”
“,” ")))
DeclareChunk = newchunk[1]
if self:GoodName(DeclareVar) then
Msg("Declare: “…DeclareVar…”
")
Msg("As: “…DeclareChunk…”
“)
else
Msg(“ERROR: Invalid variable name '”…DeclareVar…”’
")
end
DeclareChunk = “”
end
if !Ret then
chunk = chunk…v
end
Ret = false
end
end
function bbpl:GoodName(str)
local chars = string.Explode("",str)
for k,v in pairs(chars) do
local b = string.byte(v)
if !((b>=65 and b<=122) or (b>=49 and b<=57)) then
return false
end
end
return true
end
function bbpl:DoFunction(name,args)
if name == “Msg” then
Msg(args[1])
end
end
function bbpl:Operations(str)
local str = string.Trim(str)
local para = string.Explode("",str) – Paranthesis
local para_op = “”
local para_after = “”
local paras = 0
local Ret = false
for k,v in pairs(para) do
if v == “)” then
paras = paras - 1
Ret = true
end
if paras > 0 then
para_op = para_op…v
Ret = true
end
if v == “(” then
paras = paras + 1
Ret = true
end
if paras <= 0 then
if string.len(para_op) > 0 then
para_after = para_after…self:Operations(para_op)
para_op = “”
Ret = true
end
end
if !Ret then
para_after = para_after…v
end
Ret = false
end
local para = string.Explode("(",para_after) – Paranthesis
local minus = string.Explode("-",para_after)
if #minus > 1 then
local minus_after = 0
for k,v in pairs(minus) do
if k == 1 then
minus_after = tonumber(self:Operations(v))
else
minus_after = minus_after - tonumber(self:Operations(v))
end
end
return minus_after
end
local add = string.Explode("+",para_after)
if #add > 1 then
local add_after = 0
for k,v in pairs(add) do
if k == 1 then
add_after = tonumber(self:Operations(v))
else
add_after = add_after + tonumber(self:Operations(v))
end
end
return add_after
end
local divide = string.Explode("/",para_after)
if #divide > 1 then
local divide_after = 0
for k,v in pairs(divide) do
if k == 1 then
divide_after = tonumber(self:Operations(v))
else
divide_after = divide_after / tonumber(self:Operations(v))
end
end
return divide_after
end
local multiply = string.Explode("*",para_after)
if #multiply > 1 then
local multiply_after = 0
for k,v in pairs(multiply) do
if k == 1 then
multiply_after = tonumber(self:Operations(v))
else
multiply_after = multiply_after * tonumber(self:Operations(v))
end
end
return multiply_after
end
local exponent = string.Explode("^",para_after)
if #exponent > 1 then
local exponent_after = 0
for k,v in pairs(exponent) do
if k == 1 then
exponent_after = tonumber(self:Operations(v))
else
exponent_after = exponent_after ^ tonumber(self:Operations(v))
end
end
return exponent_after
end
return para_after
–[[if string.Left(str,1) == “”" then
if string.Right(str,1) == “”" then
else
end
end]]
end
function bbpl:Paranthesis(str)
end
function runfiles( player, command, arguments )
bbpl:DoString( file.Read(“bbpl/TEST.txt”) )
end
concommand.Add( “runfile”, runfiles )[/lua]
I’m a horrible coder, this thing looks like a giant mess. Hope it helps somebody.