ID:2756903
 
var syntax = \
@{" var(a,3) var(b,7) var(c,add(a,b)) var(d,list(1,7,3,8,2,5,2)) print("<b><u>[a] + [b] = [c]") for(i in d){ print("<tt>i = [i]") } print("Inserting a & b into d") insert(d,a,b) for(i in d){ print("<tt>i = [i]") } for(x = a to b){ for(y = a to b){ print("xy = [x],[y] lol") } } "}

proc/Parse(raw)
var list/tokens
var list/variables = new
var list/ram = new
var a,b,c,i
for()
a = findtext(raw,"\""); b = findtext(raw,"\"",a+1)
if(!a||!b){break}; c = copytext(raw,a+1,b)
ram["s[ram.len+1]"] = c; raw = copytext(raw,1,a) + " s[ram.len] " + copytext(raw,b+1)
raw = replacetext(raw,"\n"," ")
raw = replacetext(raw," "," ")
raw = replacetext(raw," "," ")
raw = replacetext(raw," "," ")
for()
a = findlasttext(raw,"("); b = findtext(raw,")",a+1)
if(!a||!b){break}; c = copytext(raw,a+1,b)
c = replacetext(c," ",",")
c = splittext(c,",")
for(. in c){if(!.){c-=.}}
for(i = 1 to c:len)
if(c[i] in ram)
c[i] = ram[c[i]]
ram["p[ram.len+1]"] = c; raw = copytext(raw,1,a) + " p[ram.len] " + copytext(raw,b+1)
for()
a = findlasttext(raw,"{"); b = findtext(raw,"}",a+1)
if(!a||!b){break}
c = copytext(raw,a+1,b)
c = splittext(c," ")
for(. in c){if(!.){c-=.}}
ram["b[ram.len+1]"] = c; raw = copytext(raw,1,a) + " b[ram.len] " + copytext(raw,b+1)
tokens = splittext(raw," ")
for(. in tokens){if(!.){tokens-=.}}
return list(tokens,ram,variables)

proc/Execute(list/t,list/r,list/v)
if(0)
world << "<tt><b>RUN</b>([jointext(t," ")])"
var l,a,b,c,d
var ret
for(var/p = 1 to t.len)
switch(t[p])
if("insert")
l = r[t[p+1]]
for(a = 2 to l:len)
if(l[a] in v)
l[a] = v[l[a]]
v[l[1]] += l:Copy(2)
if("print")
l = t[p+1]
if(l in r)
l = r[l][1]
world << FixString(l,r,v)
if("add")
l = t[p+1]; b = 0
for(a in l)
if(a in v){a = v[a]}
b += text2num(a)
ret = b
if("list")
ret = t[p+1]
if("var")
l = t[p+1]
if(l in r)
l = r[l]
a = l[1]
b = l[2]
if(b in v){ret = v[b]}
else
if((ret = text2num(b)) == null)
ret = Execute(list(b,r[t[p+1]][3]),r,v)
v[a[1]] = ret
if("for")
l = r[t[p+1]]
switch(l:len)
if(3)
a = l[1]
b = l[3]
if(b in v){b = v[b]}
switch(l[2])
if("in")
for(c in b)
v[a] = c
Execute(r[t[p+2]],r,v)
if(5)
a = l[1]
b = l[3];if(b in v){b = v[b]};b=text2num(b)
c = l[5];if(c in v){c = v[c]};c=text2num(c)
for(d = b to c)
v[a] = d
Execute(r[t[p+2]],r,v)
return ret

proc/FixString(string,list/r,list/v)
var a,b,c
for()
a = findtext(string,"\[")
b = findtext(string,"]")
if(!a||!b){break}
c = copytext(string,a+1,b)
if(c in v){c = v[c]}
string = copytext(string,1,a) + "[c]" + copytext(string,b+1)
return string

mob/verb/DEMO()
Execute(arglist(Parse(syntax)))


Should be able to copy and paste it, there's a verb called DEMO which will execute the variable defined at the top of the code with bits of script already in there to tinker with.

It's split into 3 seperate functions.

Parse(raw_script_goes_here_as_a_string)
This parses the raw text into a format I'm able to deal with.

Execute(tokens, list/ram, list/variables)
This executes the tokens in order starting from 1 (currently) which then will continue until a function is found and then calls itself recursively.
Ram stores all the information about the tokens in a format that can be easily parsed.
Variables stores variables :D

FixString(string,ram,variables)
This fixes the string so that variables and functions inside of [] execute and updated as needed.


Updated