Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function compFile()
- print("File too compile from:")
- filename = read()
- reader=fs.open(filename,"r") -- Opening the fle to read from
- print("File too output too:")
- name = read()
- f=fs.open(name,"a") -- Opening the file too write/append too
- datTab={} -- Establishing the table of which things are parsed itno
- print("Compiling now.")
- while true do -- The primary loop of which the prgoram is compiled in
- line = reader.readLine() -- This reads the line
- if (not line) then f.close() os.reboot() break end -- This checks and makes it stop when there is a blank line
- datTab = strutils.seperate(line," ") -- This breaks up the line by spaces
- -- Base Commands Here
- if datTab[1]=="echo" then f.writeLine("print("..datTab[2]..")") -- echo "texthere"
- elseif datTab[1]=="var" then f.writeLine(datTab[2].."="..datTab[3]) -- var x 5
- elseif datTab[1]=="if" then f.writeLine("if "..datTab[2]..datTab[3]..datTab[4].." then ") -- if x == 4
- elseif datTab[1]=="seal" and datTab[2]=="condition" then f.writeLine("end") -- seal if
- elseif datTab[1]=="math" then f.writeLine(datTab[2].."="..datTab[3]..datTab[4]..datTab[5]) -- math x 4 + 6
- elseif datTab[1]=="loop" and datTab[2]=="begin" then f.writeLine("repeat") -- loop
- elseif datTab[1]=="condition" then f.writeLine("until "..datTab[2]..datTab[3]..datTab[4]) -- condition x == 5
- elseif datTab[1]=="function" then f.writeLine("function "..datTab[2].."()") -- function functionname
- elseif datTab[1]=="call" then f.writeLine(datTab[2].."()")
- elseif datTab[1]==("raw" or "lua") then f.writeLine(datTab[2])
- elseif datTab[1]==("rem" or "//") then f.writeLine("--"..datTab[2])
- -- Rednet Commands Here
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="openport" and datTab[3]=="all" then f.writeLine("rednet.open('right') rednet.open('left') rednet.open('top') rednet.open('back')") -- net openport all
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="openport" and datTab[3]~="all" then f.writeLine("rednet.open('"..datTab[3].."')") -- net openport side
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="send" then f.writeLine("rednet.send("..datTab[3]..",('"..datTab[4].."')") -- net send id message
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="close" and datTab[3]=="all" then f.writeLine("rednet.close('back') rednet.close('top') rednet.close('left') rednet.close('right')") -- net close all
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="close" and datTab[3]~="all" then f.writeLine("rednet.close('"..datTab[4].."')") -- net close side
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="test" then f.writeLine("rednet.announce()") -- net test
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="broadcast" then f.writeLine("rednet.broadcast('"..datTab[3].."')") -- net broadcast message
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="receive" then f.writeLine(datTab[3]..","..datTab[4]..","..datTab[5].."=rednet.receive("..datTab[6]..")") -- net receive varnameid varnamemessage varnamedistance time
- -- Peripheral Commands Here
- elseif datTab[1]==("external" or "peripheral") and datTab[2]=="present" then f.writeLine("peripheral.isPresent('"..datTab[3].."')") -- external present side
- elseif datTab[1]==("external" or "peripheral") and datTab[2]=="wrap" then f.writeLine("peripheral.wrap('"..datTab[3].."')") -- external wrap side
- elseif datTab[1]==("external" or "peripheral") and datTab[2]=="type" then f.writeLine("peripheral.getType('"..datTab[3].."')") -- external type side
- -- Disk Commands Here
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="ispresent" then f.writeLine("if disk.isPresent('"..datTab[3].."') then") -- disk ispresent side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="hasdata" then f.writeLine("if disk.hasData('"..datTab[3].."') then") -- disk hasdata side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="findlabel" then f.writeLine(datTab[3].."=disk.getLabel('"..datTab[4].. "')") -- disk findlabel varname side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="setlabel" then f.writeLine("disk.setLabel("..datTab[3]..","..datTab[4]..")") -- disk setlabel side name
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="eject" then f.writeLine("disk.eject('"..datTab[3].."')") -- disk eject side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="playmusic" then f.writeLine("disk.playAudio('"..datTab[3].."')") -- disk playmusic side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="stopmusic" then f.writeLine("disk.stopAudio('"..datTab[3].."')") -- disk stopmusic side
- -- Redstone/Cable Commands Here
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="raw" and datTab[3]=="get" then f.writeLine(datTab[5]"=redstone.getInput('"..datTab[4].."')") -- redstone raw get side varname
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="raw" and datTab[3]=="set" then f.writeLine("redstone.setOutput("..datTab[4]..","..datTab[5]..")") -- redstone raw set left true
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="cable" and datTab[3]=="set" then f.writeLine("redstone.setBundledOutput("..datTab[4]..", colors."..datTab[5]..")") -- redstone cable set side color
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="cable" and datTab[3]=="wipe" then f.writeLine("redstone.setBundledOutput("..datTab[4]..", 0)") -- redstone cable wipe side
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="cable" and datTab[3]=="get" then f.writeLine(datTab[4]"=colors.test(redstone.getBundledInput('"..datTab[5].."'), colors."..datTab[6]..")") -- redstone cable get varname side color
- -- Shell and Terminal Commands Here
- elseif datTab[1]=="run" then f.writeLine("shell.run('"..datTab[2]..","..datTab[3].."')") -- run programname arguments
- elseif datTab[1]=="exit" and datTab[2]=="program" then f.writeLine("shell.exit()") -- exit program
- elseif datTab[1]=="clear" and datTab[2]=="screen" then f.writeLine("term.clear()")
- elseif datTab[1]=="clear" and datTab[2]=="line" then f.writeLine("term.clearLine()")
- elseif datTab[1]=="get" and datTab[2]=="cursor" then f.writeLine(datTab[3]..","..datTab[4].."=term.getCursorPos()") -- get cursor xvarname yvarname
- elseif datTab[1]=="set" and datTab[2]=="cursor" then f.writeLine("term.setCursorPos("..datTab[3]..","..datTab[4]..")") -- get cursor xvarname yvarname
- elseif datTab[1]=="blink" and datTab[2]=="set" then f.writeLine("term.setCursorBlink("..datTab[3]..")")
- elseif datTab[1]=="get" and datTab[2]=="terminal" and datTab[2]=="size" then f.writeLine(datTab[4]..","..datTab[5].."=term.getSize()") -- get terminal size xvarname yvarname
- elseif datTab[1]=="redirect" and datTab[2]=="monitor" then f.writeLine("term.redirect("..datTab[3]..")") -- redirect monitor size
- elseif datTab[1]=="redirect" and datTab[2]=="terminal" then f.writeLine("term.restore()") -- redirect terminal
- -- OS Commands Here
- elseif datTab[1]=="version" then f.writeLine(datTab[2].."=os.version()") -- version varname
- elseif datTab[1]=="id" then f.writeLine(datTab[2].."=os.computerID()") -- id varname
- elseif datTab[1]==("loadapi" or "include") then f.writeLine("os.loadAPI('"..datTab[2].."')") -- loadapi apiname
- elseif datTab[1]==("unloadapi" or "disinclude") then f.writeLine("os.unloadAPI('"..datTab[2].."')") -- unloadapi apiname
- elseif datTab[1]=="getstring" then f.writeLine(datTab[2].."=read()") -- getstring varname
- elseif datTab[1]==("cputime" or "clock")then f.writeLine(datTab[2].."=os.clock()") -- cputime varname
- elseif datTab[1]=="sleep" then f.writeLine("sleep("..datTab[2]..")") -- sleep 5
- elseif datTab[1]=="time" then f.writeLine(datTab[2].."=os.time()") -- time varname
- elseif datTab[1]=="shutdown" and datTab[2]=="computer" then f.writeLine("os.shutdown()") -- shutdown computer
- elseif datTab[1]=="reboot" and datTab[2]=="computer" then f.writeLine("os.reboot()") -- reboot computer
- -- Fs/Io Commands Here
- elseif datTab[1]=="list" then f.writeLine(datTab[3].."=fs.list('"..datTab[2].."')") -- list path/here/for/whatevers varname
- elseif datTab[1]=="exists" then f.writeLine(datTab[3].."=fs.exists('"..datTab[2].."')") -- exists path/here/for/whatevers varname
- elseif datTab[1]=="isreadonly" then f.writeLine(datTab[3].."=fs.isReadOnly('"..datTab[2].."')") -- isreadonly path/here/for/whatevers varname
- elseif datTab[1]==("getname" or "fetchname") then f.writeLine(datTab[3].."=fs.getName('"..datTab[2].."')") -- getname path/here/for/whatevers varname
- elseif datTab[1]==("makedir" or "mdir") then f.writeLine("fs.makeDir('"..datTab[2].."')") -- makedir path/here/for/whatevers
- elseif datTab[1]=="move" then f.writeLine("fs.move('"..datTab[2].."','"..datTab[3].."')") -- move path/A path/B
- elseif datTab[1]=="copy" then f.writeLine("fs.copy('"..datTab[2].."','"..datTab[3].."')") -- copy path/A path/B
- elseif datTab[1]=="delete" then f.writeLine("fs.delete('"..datTab[2].."')") -- delete path/here/for/whatevers
- elseif datTab[1]=="open" then f.writeLine(datTab[2].."=fs.open('"..datTab[3]..",'"..datTab[4].."')") -- open varname path/here/for/whatevers mode
- -- Math Commands Here
- elseif datTab[1]==("random" or "rand") then f.writeLine(datTab[2].."=math.random("..datTab[3]..")") -- random varname maxnumber
- elseif datTab[1]==("absolute" or "abs") then f.writeLine(datTab[2].."math.abs("..datTab[3]..")") -- absolute varname number
- elseif datTab[1]==("ceiling" or "ceil") then f.writeLine(datTab[2].."=math.ceil("..datTab[3]..")") -- ceiling varname number
- elseif datTab[1]=="floor" then f.writeLine(datTab[2].."=math.floor("..datTab[3]..")") -- floor varname number
- elseif datTab[1]==("power" or "pow") then f.writeLine(datTab[2].."=math.pow("..datTab[3]..","..datTab[4]..")") -- power varname numbera numberb
- elseif datTab[1]=="pi" then f.writeLine(datTab[2].."=math.pi()") -- pi varname
- elseif datTab[1]==("squareroot" or "sqrt") then f.writeLine(datTab[2].."=math.sqrt("..datTab[3]..")") -- squareroot varname number
- else print("ERROR: INCORRECT SYNTAX") -- Error code here
- end
- end
- end
- function interpFile()
- state = "running" -- This is what I use to maintain the loop
- repeat -- Beginning the loop of which the code is interpreted in
- input = read() -- Harvesting the input
- datTab=nil -- Making sure that the table is blank and won't have any interruptions
- datTab={} -- Establishing the table of which the data is parsed into
- if input=="exit" then f.close() os.reboot() end -- Checking for the exit command
- if input~=nil then datTab = strutils.seperate(input," ") -- Making sure that the datTab table doesnt get any blank lines
- if datTab[1]=="echo" then f.writeLine("print("..datTab[2]..")") -- echo "texthere"
- elseif datTab[1]=="var" then f.writeLine(datTab[2].."="..datTab[3]) -- var x 5
- elseif datTab[1]=="if" then f.writeLine("if "..datTab[2]..datTab[3]..datTab[4].." then ") -- if x == 4
- elseif datTab[1]=="seal" and datTab[2]=="condition" then f.writeLine("end") -- seal if
- elseif datTab[1]=="math" then f.writeLine(datTab[2].."="..datTab[3]..datTab[4]..datTab[5]) -- math x 4 + 6
- elseif datTab[1]=="loop" and datTab[2]=="begin" then f.writeLine("repeat") -- loop
- elseif datTab[1]=="condition" then f.writeLine("until "..datTab[2]..datTab[3]..datTab[4]) -- condition x == 5
- elseif datTab[1]=="function" then f.writeLine("function "..datTab[2].."()") -- function functionname
- elseif datTab[1]=="call" then f.writeLine(datTab[2].."()")
- elseif datTab[1]==("raw" or "lua") then f.writeLine(datTab[2])
- elseif datTab[1]==("rem" or "//") then f.writeLine("--"..datTab[2])
- -- Rednet Commands Here
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="openport" and datTab[3]=="all" then f.writeLine("rednet.open('right') rednet.open('left') rednet.open('top') rednet.open('back')") -- net openport all
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="openport" and datTab[3]~="all" then f.writeLine("rednet.open('"..datTab[3].."')") -- net openport side
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="send" then f.writeLine("rednet.send("..datTab[3]..",('"..datTab[4].."')") -- net send id message
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="close" and datTab[3]=="all" then f.writeLine("rednet.close('back') rednet.close('top') rednet.close('left') rednet.close('right')") -- net close all
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="close" and datTab[3]~="all" then f.writeLine("rednet.close('"..datTab[4].."')") -- net close side
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="test" then f.writeLine("rednet.announce()") -- net test
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="broadcast" then f.writeLine("rednet.broadcast('"..datTab[3].."')") -- net broadcast message
- elseif datTab[1]==("net" or "rednet") and datTab[2]=="receive" then f.writeLine(datTab[3]..","..datTab[4]..","..datTab[5].."=rednet.receive("..datTab[6]..")") -- net receive varnameid varnamemessage varnamedistance time
- -- Peripheral Commands Here
- elseif datTab[1]==("external" or "peripheral") and datTab[2]=="present" then f.writeLine("peripheral.isPresent('"..datTab[3].."')") -- external present side
- elseif datTab[1]==("external" or "peripheral") and datTab[2]=="wrap" then f.writeLine("peripheral.wrap('"..datTab[3].."')") -- external wrap side
- elseif datTab[1]==("external" or "peripheral") and datTab[2]=="type" then f.writeLine("peripheral.getType('"..datTab[3].."')") -- external type side
- -- Disk Commands Here
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="ispresent" then f.writeLine("if disk.isPresent('"..datTab[3].."') then") -- disk ispresent side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="hasdata" then f.writeLine("if disk.hasData('"..datTab[3].."') then") -- disk hasdata side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="findlabel" then f.writeLine(datTab[3].."=disk.getLabel('"..datTab[4].. "')") -- disk findlabel varname side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="setlabel" then f.writeLine("disk.setLabel("..datTab[3]..","..datTab[4]..")") -- disk setlabel side name
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="eject" then f.writeLine("disk.eject('"..datTab[3].."')") -- disk eject side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="playmusic" then f.writeLine("disk.playAudio('"..datTab[3].."')") -- disk playmusic side
- elseif datTab[1]==("disk" or "disc") and datTab[2]=="stopmusic" then f.writeLine("disk.stopAudio('"..datTab[3].."')") -- disk stopmusic side
- -- Redstone/Cable Commands Here
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="raw" and datTab[3]=="get" then f.writeLine(datTab[5]"=redstone.getInput('"..datTab[4].."')") -- redstone raw get side varname
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="raw" and datTab[3]=="set" then f.writeLine("redstone.setOutput("..datTab[4]..","..datTab[5]..")") -- redstone raw set left true
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="cable" and datTab[3]=="set" then f.writeLine("redstone.setBundledOutput("..datTab[4]..", colors."..datTab[5]..")") -- redstone cable set side color
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="cable" and datTab[3]=="wipe" then f.writeLine("redstone.setBundledOutput("..datTab[4]..", 0)") -- redstone cable wipe side
- elseif datTab[1]==("redstone" or "rs") and datTab[2]=="cable" and datTab[3]=="get" then f.writeLine(datTab[4]"=colors.test(redstone.getBundledInput('"..datTab[5].."'), colors."..datTab[6]..")") -- redstone cable get varname side color
- -- Shell and Terminal Commands Here
- elseif datTab[1]=="run" then f.writeLine("shell.run('"..datTab[2]..","..datTab[3].."')") -- run programname arguments
- elseif datTab[1]=="exit" and datTab[2]=="program" then f.writeLine("shell.exit()") -- exit program
- elseif datTab[1]=="clear" and datTab[2]=="screen" then f.writeLine("term.clear()")
- elseif datTab[1]=="clear" and datTab[2]=="line" then f.writeLine("term.clearLine()")
- elseif datTab[1]=="get" and datTab[2]=="cursor" then f.writeLine(datTab[3]..","..datTab[4].."=term.getCursorPos()") -- get cursor xvarname yvarname
- elseif datTab[1]=="set" and datTab[2]=="cursor" then f.writeLine("term.setCursorPos("..datTab[3]..","..datTab[4]..")") -- get cursor xvarname yvarname
- elseif datTab[1]=="blink" and datTab[2]=="set" then f.writeLine("term.setCursorBlink("..datTab[3]..")")
- elseif datTab[1]=="get" and datTab[2]=="terminal" and datTab[2]=="size" then f.writeLine(datTab[4]..","..datTab[5].."=term.getSize()") -- get terminal size xvarname yvarname
- elseif datTab[1]=="redirect" and datTab[2]=="monitor" then f.writeLine("term.redirect("..datTab[3]..")") -- redirect monitor size
- elseif datTab[1]=="redirect" and datTab[2]=="terminal" then f.writeLine("term.restore()") -- redirect terminal
- -- OS Commands Here
- elseif datTab[1]=="version" then f.writeLine(datTab[2].."=os.version()") -- version varname
- elseif datTab[1]=="id" then f.writeLine(datTab[2].."=os.computerID()") -- id varname
- elseif datTab[1]==("loadapi" or "include") then f.writeLine("os.loadAPI('"..datTab[2].."')") -- loadapi apiname
- elseif datTab[1]==("unloadapi" or "disinclude") then f.writeLine("os.unloadAPI('"..datTab[2].."')") -- unloadapi apiname
- elseif datTab[1]=="getstring" then f.writeLine(datTab[2].."=read()") -- getstring varname
- elseif datTab[1]==("cputime" or "clock")then f.writeLine(datTab[2].."=os.clock()") -- cputime varname
- elseif datTab[1]=="sleep" then f.writeLine("sleep("..datTab[2]..")") -- sleep 5
- elseif datTab[1]=="time" then f.writeLine(datTab[2].."=os.time()") -- time varname
- elseif datTab[1]=="shutdown" and datTab[2]=="computer" then f.writeLine("os.shutdown()") -- shutdown computer
- elseif datTab[1]=="reboot" and datTab[2]=="computer" then f.writeLine("os.reboot()") -- reboot computer
- -- Fs/Io Commands Here
- elseif datTab[1]=="list" then f.writeLine(datTab[3].."=fs.list('"..datTab[2].."')") -- list path/here/for/whatevers varname
- elseif datTab[1]=="exists" then f.writeLine(datTab[3].."=fs.exists('"..datTab[2].."')") -- exists path/here/for/whatevers varname
- elseif datTab[1]=="isreadonly" then f.writeLine(datTab[3].."=fs.isReadOnly('"..datTab[2].."')") -- isreadonly path/here/for/whatevers varname
- elseif datTab[1]==("getname" or "fetchname") then f.writeLine(datTab[3].."=fs.getName('"..datTab[2].."')") -- getname path/here/for/whatevers varname
- elseif datTab[1]==("makedir" or "mdir") then f.writeLine("fs.makeDir('"..datTab[2].."')") -- makedir path/here/for/whatevers
- elseif datTab[1]=="move" then f.writeLine("fs.move('"..datTab[2].."','"..datTab[3].."')") -- move path/A path/B
- elseif datTab[1]=="copy" then f.writeLine("fs.copy('"..datTab[2].."','"..datTab[3].."')") -- copy path/A path/B
- elseif datTab[1]=="delete" then f.writeLine("fs.delete('"..datTab[2].."')") -- delete path/here/for/whatevers
- elseif datTab[1]=="open" then f.writeLine(datTab[2].."=fs.open('"..datTab[3]..",'"..datTab[4].."')") -- open varname path/here/for/whatevers mode
- -- Math Commands Here
- elseif datTab[1]==("random" or "rand") then f.writeLine(datTab[2].."=math.random("..datTab[3]..")") -- random varname maxnumber
- elseif datTab[1]==("absolute" or "abs") then f.writeLine(datTab[2].."math.abs("..datTab[3]..")") -- absolute varname number
- elseif datTab[1]==("ceiling" or "ceil") then f.writeLine(datTab[2].."=math.ceil("..datTab[3]..")") -- ceiling varname number
- elseif datTab[1]=="floor" then f.writeLine(datTab[2].."=math.floor("..datTab[3]..")") -- floor varname number
- elseif datTab[1]==("power" then or "pow") f.writeLine(datTab[2].."=math.pow("..datTab[3]..","..datTab[4]..")") -- power varname numbera numberb
- elseif datTab[1]=="pi" then f.writeLine(datTab[2].."=math.pi()") -- pi varname
- elseif datTab[1]==("squareroot" or "sqrt") then f.writeLine(datTab[2].."=math.sqrt("..datTab[3]..")") -- squareroot varname number
- else print("ERROR: INCORRECT SYNTAX") -- Error code here
- end
- end
- until state~="running" -- Checking for if the loop has been broken
- end
- function interpBegin() -- A precursor/preperation function for the actual interpFile()
- print("Name of file too output too:")
- local name=read()
- f=fs.open(name,"a") -- Opening the file too write/append too
- datTab={}
- print("Begin your scripting:")
- print("_____________________")
- interpFile() -- Calling the main interpreter function
- end
- function intro() -- The primary introduction function
- term.clear() -- Clearing the screen
- term.setCursorPos(1,1) -- Setting the cursor position
- print("Welcome to the RedScript Scripting Tool") -- Presenting the information about the input
- print("1 - Interpreter")
- print("2 - Compiler")
- while true do -- The input loop
- event, p1 = os.pullEvent() -- Harvesting input
- if event=="char" and p1=="1" then interpBegin() -- Checking for if they want too interpret
- elseif event=="char" and p1=="2" then compFile() -- Or if they want too compile
- end
- end
- end
- intro() -- Calling the introduction function
Advertisement
Add Comment
Please, Sign In to add comment