Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defList={};
- local fout;
- function parsePoundStatement(str)
- local val,a,b,c,d;
- for val,a,b,d,c in string.gmatch(str,"#(%a+)(%s+)(%a+)(%s+)(.-)$") do
- if val=="define" and a and b and c then
- defList[b]=c;
- -- print(b.." == "..defList[b])
- end
- end
- end
- function parseRegularStatement(line)
- local oline=line
- line =line.." "
- for text, expr in string.gmatch(line, "([%a_]+)([%s;,:\(\)]+)") do
- if defList[text]~=nil then
- --print(text.." found")
- oline=string.gsub(oline,text,defList[text],1);
- else
- -- print(text.." not found")
- end
- end
- fout.writeLine(oline)
- --print(oline);
- return oline
- end
- function readMacroFile(fn)
- if fn== nil then fn="macros" end
- if not fs.exists(fn) then
- shell.run("pastebin get ycMm8L5N "..fn)
- end
- local f= fs.open(fn,"r")
- local line;
- repeat
- line= f.readLine()
- if(line~=nil) then
- if string.gmatch(line,"^#(.*)")~=nil then
- parsePoundStatement(line)
- end
- end
- until line==nil
- end
- readMacroFile()
- --[[
- parsePoundStatement("#define rpt repeat")
- parsePoundStatement("#define utl until")
- parsePoundStatement("#define els else")
- parsePoundStatement("#define eif elseif")
- parsePoundStatement("#define whi while")
- parsePoundStatement("#define tpf turtle.place()")
- parsePoundStatement("#define tpd turtle.placeDown()")
- parsePoundStatement("#define tpu turtle.placeUp()")
- parsePoundStatement("#define tmf turtle.forward()")
- parsePoundStatement("#define tmd turtle.down()")
- parsePoundStatement("#define tmu turtle.up()")
- parsePoundStatement("#define tmb turtle.back()")
- parsePoundStatement("#define ttl turtle.turnLeft()")
- parsePoundStatement("#define ttr turtle.turnRight()")
- parsePoundStatement("#define txf turtle.dig()")
- parsePoundStatement("#define txu turtle.digUp()")
- parsePoundStatement("#define txd turtle.digDown()")
- parsePoundStatement("#define tdf turtle.drop()")
- parsePoundStatement("#define tdd turtle.dropDown()")
- parsePoundStatement("#define tdu turtle.dropUp()")
- --]]
- local str=""
- local k=1;
- local args={...}
- function help()
- print("<object><function><dirction>")
- print("objects [r]edstone [t]urtle>")
- print("redstone :[g]et [s]et [c]lear")
- print("turtle: x=dig [m]ove [d]rop [p]lace")
- print("l=detect sl=select [c]ompare")
- end
- if #args ==0 then
- help()
- while true do
- print("entering string mode")
- fout=fs.open("tempscr"..k,"w")
- str=read();
- if(str=="quit") then break
- elseif str=="help" then help() end
- --print("str="..str)
- parseRegularStatement(str)
- fout.close()
- shell.run("tempscr"..k)
- k=k+1
- end
- else
- local fnin=args[1]
- local fnout=args[2]
- local fin
- if fnout ==nil then fnout="outscr"end
- if not fs.exists(fnin) then print(fnin.." not found"); error() end
- fin=fs.open(fnin,"r")
- fout=fs.open(fnout,"w")
- while true do
- str=fin.readLine()
- if str~=nil then parseRegularStatement(str)
- else break end
- end
- fin.close()
- fout.close()
- end
Advertisement
Add Comment
Please, Sign In to add comment