Advertisement
shadowkat1010

SScript

Nov 26th, 2012
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.33 KB | None | 0 0
  1. --I trimmed it a little :P
  2. --Start of StrUtils
  3. --[[
  4. Copyright (C) 2012 Thomas Farr a.k.a tomass1996 [farr.thomas@gmail.com]
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  7. associated documentation files (the "Software"), to deal in the Software without restriction,
  8. including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. copies of the Software, and to permit persons to whom the Software is furnished to do so,
  10. subject to the following conditions:
  11.  
  12. -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  13. -Visible credit is given to the original author.
  14. -The software is distributed in a non-profit way.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  17. WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  18. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. --]]
  21. function find(str, match, startIndex)  --Finds @match in @str optionally after @startIndex
  22.     if not match then return nil end
  23.     str = tostring(str)
  24.     local _ = startIndex or 1
  25.     local _s = nil
  26.     local _e = nil
  27.     local _len = match:len()
  28.     while true do
  29.         local _t = str:sub( _ , _len + _ - 1)
  30.         if _t == match then
  31.             _s = _
  32.             _e = _ + _len - 1
  33.             break
  34.         end
  35.         _ = _ + 1
  36.         if _ > str:len() then break end
  37.     end
  38.     if _s == nil then return nil else return _s, _e end
  39. end
  40. function seperate(str, divider)  --Separates @str on @divider
  41.     if not divider then return nil end
  42.     str = tostring(str)
  43.     local start = {}
  44.     local endS = {}
  45.     local n=1
  46.     repeat
  47.         if n==1 then
  48.             start[n], endS[n] = find(str, divider)
  49.         else
  50.             start[n], endS[n] = find(str, divider, endS[n-1]+1)
  51.         end
  52.         n=n+1
  53.     until start[n-1]==nil
  54.     local subs = {}
  55.     for n=1, #start+1 do
  56.         if n==1 then
  57.             subs[n] = str:sub(1, start[n]-1)
  58.         elseif n==#start+1 then
  59.             subs[n] = str:sub(endS[n-1]+1)
  60.         else
  61.             subs[n] = str:sub(endS[n-1]+1, start[n]-1)
  62.         end
  63.     end
  64.     return subs
  65. end
  66. --End of StrUtils
  67. tArgs = {...}
  68.     function compFile()
  69.     filename = tArgs[2]
  70.     name = tArgs[3]
  71.     reader = fs.open(filename,"r")
  72.     f=fs.open(name,"a") -- Opening the file too write/append too
  73.     datTab={} -- Establishing the table of which things are parsed itno
  74.     while true do -- The primary loop of which the prgoram is compiled in
  75.             line = reader.readLine() -- This reads the line
  76.             if (not line) then f.close() os.reboot() break end -- This checks and makes it stop when there is a blank line
  77.             datTab = seperate(line," ") -- This breaks up the line by spaces
  78.               -- Base Commands Here
  79.                     if datTab[1]=="echo" then f.writeLine("print("..datTab[2]..")")  -- echo "texthere"
  80.                     elseif datTab[1]=="var" then f.writeLine(datTab[2].." = "..datTab[3]) -- var x 5
  81.                     elseif datTab[1]=="if" and datTab[2]=="create" then f.writeLine("if "..datTab[3].." "..datTab[4].." "..datTab[5].." then ") -- if x == 4
  82.                     elseif datTab[1]=="if" and datTab[2]=="add" then f.writeLine("elseif "..datTab[3].." "..datTab[4].." "..datTab[5].." then") --if add x == 4
  83.                     elseif datTab[1]=="if" and datTab[2]=="otherwise" then f.writeLine("else")
  84.                     elseif datTab[1]=="if" and datTab[2]=="seal" then f.writeLine("end") -- if seal
  85.                     elseif datTab[1]=="math" then f.writeLine(datTab[2].." = "..datTab[3].." "..datTab[4].." "..datTab[5]) -- math x 4 + 6
  86.                     elseif datTab[1]=="loop" and datTab[2]=="begin" then f.writeLine("repeat") -- loop
  87.                     elseif datTab[1]=="loop" and datTab[2]=="end" and datTab[3]=="never" then f.writeLine("until nil ~= nil") -- condition x == 5
  88.                     elseif datTab[1]=="loop" and datTab[2]=="end" and datTab[3]~="never" then f.writeLine("until "..datTab[4].." "..datTab[5].." "..datTab[6])
  89.                     elseif datTab[1]=="chunk" and datTab[2]=="create" then f.writeLine("function "..datTab[3].."()") -- chunk create chunkname
  90.                     elseif datTab[1]=="chunk" and datTab[2]=="run" then f.writeLine(datTab[3].."()") -- chunk run chunkname
  91.                     elseif datTab[1]=="custom" then f.writeLine(datTab[2]) -- custom printer.drawChar(1,1,"H")
  92.                     elseif datTab[1]=="#" then f.writeLine("-- "..datTab[2]) -- # "this is a comment"
  93.             -- Rednet Commands Here
  94.                     elseif datTab[1]=="lan" or datTab[1]=="LAN" and datTab[2]=="connect" and datTab[3]=="all" then f.writeLine("rednet.open('right') rednet.open('left') rednet.open('top') rednet.open('back')") -- lan connect all
  95.                     elseif datTab[1]=="lan" or datTab[1]=="LAN" and datTab[2]=="connect" and datTab[3]~="all" then f.writeLine("rednet.open('"..datTab[3].."')") -- lan connect side
  96.                     elseif datTab[1]=="lan" or datTab[1]=="LAN" and datTab[2]=="send" then f.writeLine("rednet.send("..datTab[3]..",('"..datTab[4].."')") -- lan send id message
  97.                     elseif datTab[1]=="lan" or datTab[1]=="LAN" and datTab[2]=="disconnect" and datTab[3]=="all" then f.writeLine("rednet.close('back') rednet.close('top') rednet.close('left') rednet.close('right')") -- lan close all
  98.                     elseif datTab[1]=="lan" or datTab[1]=="LAN" and datTab[2]=="disconnect" and datTab[3]~="all" then f.writeLine("rednet.close('"..datTab[4].."')") -- lan close side
  99.                     elseif datTab[1]=="lan" or datTab[1]=="LAN" and datTab[2]=="test" then f.writeLine("rednet.announce()") -- lan test
  100.                     elseif datTab[1]=="lan" or datTab[1]=="LAN" and datTab[2]=="broadcast" then f.writeLine("rednet.broadcast('"..datTab[3].."')") -- lan broadcast message
  101.                     elseif datTab[1]=="lan" or datTab[1]=="LAN" and datTab[2]=="receive" then f.writeLine(datTab[3]..","..datTab[4]..","..datTab[5].." = rednet.receive("..datTab[6]..")") -- lan receive varnameid varnamemessage varnamedistance timeout
  102.             -- Peripheral Commands Here
  103.                     elseif datTab[1]=="external" and datTab[2]=="present" then f.writeLine(datTab[3].." = peripheral.isPresent('"..datTab[4].."')") -- external present varname side
  104.                     elseif datTab[1]=="external" and datTab[2]=="wrap" then f.writeLine("peripheral.wrap('"..datTab[3].."')") -- external wrap side
  105.                     elseif datTab[1]=="external" and datTab[2]=="type" then f.writeLine(datTab[3].." = peripheral.getType('"..datTab[4].."')") -- external type varname side
  106.             -- Disk Commands Here
  107.                     elseif datTab[1]=="cd" and datTab[2]=="check" and datTab[3]=="exists" then f.writeLine(datTab[4].." = disk.isPresent('"..datTab[5].."') then") -- cd check exists varname side
  108.                     elseif datTab[1]=="cd" and datTab[2]=="check" and datTab[3]=="data" then f.writeLine(datTab[4].." = disk.hasData('"..datTab[5].."') then") -- cd check data varname side
  109.                     elseif datTab[1]=="cd" and datTab[2]=="check" and datTab[3]=="music" then f.writeLine(datTab[4].." = disk.hasAudio('"..datTab[5].."') then") -- cd check music varname side
  110.                     elseif datTab[1]=="cd" and datTab[2]=="get" and datTab[3]=="name" then f.writeLine(datTab[4].." = disk.getLabel('"..datTab[5].. "')") -- cd get name varname side
  111.                     elseif datTab[1]=="cd" and datTab[2]=="set" and datTab[3]=="name" then f.writeLine("disk.setLabel("..datTab[4]..","..datTab[5]..")") -- cd set name side name
  112.                     elseif datTab[1]=="cd" and datTab[2]=="eject" then f.writeLine("disk.eject('"..datTab[3].."')") -- cd eject side
  113.                     elseif datTab[1]=="cd" and datTab[2]=="play" then f.writeLine("disk.playAudio('"..datTab[3].."')") -- cd play side
  114.                     elseif datTab[1]=="cd" and datTab[2]=="stop" then f.writeLine("disk.stopAudio('"..datTab[3].."')") -- cd stop side
  115.             -- Redstone/Cable Commands Here
  116.                     elseif datTab[1]=="redstone" and datTab[2]=="raw" and datTab[3]=="get" then f.writeLine(datTab[4]" = redstone.getInput('"..datTab[5].."')") -- redstone raw get varname side
  117.                     elseif datTab[1]=="redstone" and datTab[2]=="raw" and datTab[3]=="set" then f.writeLine("redstone.setOutput("..datTab[4]..","..datTab[5]..")") -- redstone raw set left true
  118.                     elseif datTab[1]=="redstone" and datTab[2]=="cable" and datTab[3]=="set" then f.writeLine("redstone.setBundledOutput("..datTab[4]..", colors."..datTab[5]..")") -- redstone cable set side color
  119.                     elseif datTab[1]=="redstone" and datTab[2]=="cable" and datTab[3]=="wipe" then f.writeLine("redstone.setBundledOutput("..datTab[4]..", 0)") -- redstone cable wipe side
  120.                     elseif datTab[1]=="redstone" 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
  121.             -- Shell and Terminal Commands Here
  122.                     elseif datTab[1]=="run" then f.writeLine("shell.run('"..datTab[2]..","..datTab[3].."')") -- run programname arguments
  123.                     elseif datTab[1]=="exit" and datTab[2]=="program" then f.writeLine("shell.exit()") -- exit program
  124.                     elseif datTab[1]=="clear" and datTab[2]=="screen" then f.writeLine("term.clear()") f.writeLine("term.setCursorPos(1,1)")
  125.                     elseif datTab[1]=="clear" and datTab[2]=="line" then f.writeLine("term.clearLine()")
  126.                     elseif datTab[1]=="get" and datTab[2]=="cursor" then f.writeLine(datTab[3]..","..datTab[4].." = term.getCursorPos()") -- get cursor xvarname yvarname
  127.                     elseif datTab[1]=="set" and datTab[2]=="cursor" then f.writeLine("term.setCursorPos("..datTab[3]..","..datTab[4]..")") -- get cursor xvarname yvarname
  128.                     elseif datTab[1]=="set" and datTab[2]=="blink" then f.writeLine("term.setCursorBlink("..datTab[3]..")")
  129.                     elseif datTab[1]=="get" and datTab[2]=="screen" and datTab[3]=="size" then f.writeLine(datTab[4]..","..datTab[5].." = term.getSize()") -- get screen size xvarname yvarname
  130.                     elseif datTab[1]=="redirect" and datTab[2]=="monitor" then f.writeLine("term.redirect("..datTab[3]..")") -- redirect monitor size
  131.                     elseif datTab[1]=="redirect" and datTab[2]=="terminal" then f.writeLine("term.restore()") -- redirect terminal
  132.             -- OS Commands Here
  133.                     elseif datTab[1]=="version" then f.writeLine(datTab[2].." = os.version()") -- version varname
  134.                     elseif datTab[1]=="id" then f.writeLine(datTab[2].." = os.computerID()") -- id varname
  135.                     elseif datTab[1]=="api" and datTab[2]=="load" then f.writeLine("os.loadAPI('"..datTab[3].."')") -- api load apiname
  136.                     elseif datTab[1]=="api" and datTab[2]=="unload" then f.writeLine("os.unloadAPI('"..datTab[3].."')") -- api unload apiname
  137.                     elseif datTab[1]=="get" and datTab[2]=="input" then f.writeLine(datTab[3].." = read()") -- get input varname
  138.                     elseif datTab[1]=="get" and datTab[2]=="event" then f.writeLine(datTab[3].." = os.pullEvent("..datTab[4]..")") -- get event varname "filter"
  139.                     elseif datTab[1]=="cputime" then f.writeLine(datTab[2].." = os.clock()") -- cputime varname
  140.                     elseif datTab[1]=="wait" then f.writeLine("sleep("..datTab[2]..")") -- wait 5
  141.                     elseif datTab[1]=="time" then f.writeLine(datTab[2].." = os.time()") -- time varname
  142.                     elseif datTab[1]=="shutdown" and datTab[2]=="computer" then f.writeLine("fs.delete('/SSTempFile') os.shutdown()") -- shutdown computer
  143.                     elseif datTab[1]=="restart" and datTab[2]=="computer" then f.writeLine("fs.delete('/SSTempFile') os.reboot()") -- reboot computer
  144.             -- Fs/Io Commands Here
  145.                     elseif datTab[1]=="list" then f.writeLine("fs.list('"..datTab[2].."')") -- list path/here/for/whatevers
  146.                     elseif datTab[1]=="exists" then f.writeLine("fs.exists('"..datTab[2].."')") -- exists path/here/for/whatevers
  147.                     elseif datTab[1]=="isreadonly" then f.writeLine("fs.isReadOnly('"..datTab[2].."')") -- isreadonly path/here/for/whatevers
  148.                     elseif datTab[1]=="getname" then f.writeLine("fs.getName('"..datTab[2].."')") -- getname path/here/for/whatevers
  149.                     elseif datTab[1]=="make" and datTab[2]=="folder" then f.writeLine("fs.makeDir('"..datTab[3].."')") -- makedir path/here/for/whatevers
  150.                     elseif datTab[1]=="move" then f.writeLine("fs.move('"..datTab[2].."','"..datTab[3].."')") -- move path/A path/B
  151.                     elseif datTab[1]=="copy" then f.writeLine("fs.copy('"..datTab[2].."','"..datTab[3].."')") -- copy path/A path/B
  152.                     elseif datTab[1]=="delete" then f.writeLine("fs.delete('"..datTab[2].."')") -- delete path/here/for/whatevers
  153.                     elseif datTab[1]=="edit" and datTab[2]=="file" then f.writeLine(datTab[3].." = fs.open('"..datTab[4]..",'"..datTab[5].."')") -- open varname path/here/for/whatevers mode
  154.             -- Math Commands Here
  155.                     elseif datTab[1]=="random" then f.writeLine(datTab[2].."=math.random("..datTab[3]..")") -- random varname maxnumber
  156.                     elseif datTab[1]=="absolute" then f.writeLine(datTab[2].."math.abs("..datTab[3]..")") -- absolute varname number
  157.                     elseif datTab[1]=="ceiling" then f.writeLine(datTab[2].."=math.ceil("..datTab[3]..")") -- ceiling varname number
  158.                     elseif datTab[1]=="floor" then f.writeLine(datTab[2].."=math.floor("..datTab[3]..")") -- floor varname number
  159.                     elseif datTab[1]=="power" then f.writeLine(datTab[2].."=math.pow("..datTab[3]..","..datTab[4]..")") -- power varname numbera numberb
  160.                     elseif datTab[1]=="pi" then f.writeLine(datTab[2].."=math.pi()") -- pi varname
  161.                     elseif datTab[1]=="squareroot" then f.writeLine(datTab[2].."=math.sqrt("..datTab[3]..")") -- squareroot varname number
  162.            
  163.             else print("ERROR: INCORRECT SYNTAX") -- Error code here
  164.     end
  165.     end
  166.     end
  167.      
  168. if tArgs[1] == "compile" then
  169.  compFile()
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement