tommyroyall

RypScript

Oct 14th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.65 KB | None | 0 0
  1. --[[ RypScript Ideas:
  2. new public/static function functionName(argA,argB,etc);
  3. new public/static class className <extends [parent]>;
  4. set <local> type tag=value;
  5. end
  6. // Comment here
  7. def tableName;
  8.  
  9. Operators:
  10. +,-,*,/,%,+=,-= - Arithmetic Operators
  11. $ - String Concatenation
  12. ++, -- - Increment, Decrement
  13. <<, >> - Shift Directions
  14. ==, !=, <, >, <=, >= - Comparison Operators
  15. ]]--
  16.  
  17. syntax.constructors={'new','set','establish','est'}
  18.  
  19.  
  20. syntax={}
  21.  
  22. env={}
  23. env.data={}
  24. env.data_stack={}
  25. env.apis={}
  26. env.version_int=0.1
  27. env.version_int="Version: 0.1"
  28.  
  29. env.math={}
  30. env.math.pi=math.pi()
  31. env.math.inf=math.huge
  32. env.math.neginf=math.huge-math.huge-math.huge
  33.  
  34. ryp={}
  35. ryp.lang{}
  36. ryp.math{}
  37. ryp.string{}
  38. ryp.util{}
  39. ryp.file{}
  40. ryp.net{}
  41. ryp.sys={}
  42.  
  43. function translate(line) -- Tramslates the code.
  44.    
  45. end
  46. function clear() -- Clears the screen.
  47.     term.clear()
  48.     term.setCursorPos(1,1)
  49. end
  50. function printLogo() -- Prints the logo.
  51. print([[
  52.   _____             _____           _       _  
  53.  |  __ \           / ____|         (_)     | |  
  54.  | |__) |   _ _ __| (___   ___ _ __ _ _ __ | |_
  55.  |  _  / | | | '_ \\___ \ / __| '__| | '_ \| __|
  56. | | \ \ |_| | |_) |___) | (__| |  | | |_) | |_
  57. |_|  \_\__, | .__/_____/ \___|_|  |_| .__/ \__|
  58.         __/ | |                     | |        
  59.        |___/|_|                     |_|]])
  60. end
  61. function split(str, pat) -- Splits strings.
  62.   local t = {}  -- NOTE: use {n = 0} in Lua-5.0
  63.   local fpat = "(.-)" .. pat
  64.   local last_end = 1
  65.   local s, e, cap = str:find(fpat, 1)
  66.   while s do
  67.      if s ~= 1 or cap ~= "" then
  68.      table.insert(t,cap)
  69.      end
  70.      last_end = e+1
  71.      s, e, cap = str:find(fpat, last_end)
  72.   end
  73.   if last_end <= #str then
  74.      cap = str:sub(last_end)
  75.      table.insert(t, cap)
  76.   end
  77.   return t
  78. end
  79. function class(base, init) -- Establishes classes.
  80.   local c = {}    -- a new class instance
  81.   if not init and type(base) == 'function' then
  82.      init = base
  83.      base = nil
  84.   elseif type(base) == 'table' then
  85.    -- our new class is a shallow copy of the base class!
  86.      for i,v in pairs(base) do
  87.         c[i] = v
  88.      end
  89.      c._base = base
  90.   end
  91.   -- the class will be the metatable for all its objects,
  92.   -- and they will look up their methods in it.
  93.   c.__index = c
  94.  
  95.   -- expose a constructor which can be called by <classname>(<args>)
  96.   local mt = {}
  97.   mt.__call = function(class_tbl, ...)
  98.   local obj = {}
  99.   setmetatable(obj,c)
  100.   if init then
  101.      init(obj,...)
  102.   else
  103.      -- make sure that any stuff from the base class is initialized!
  104.      if base and base.init then
  105.      base.init(obj, ...)
  106.      end
  107.   end
  108.   return obj
  109.   end
  110.   c.init = init
  111.   c.is_a = function(self, klass)
  112.      local m = getmetatable(self)
  113.      while m do
  114.         if m == klass then return true end
  115.         m = m._base
  116.      end
  117.      return false
  118.   end
  119.   setmetatable(c, mt)
  120.   return c
  121. end
  122. function readFile(inFile,outFile) -- Reads the file and calls translate() line by line.
  123. input=fs.open(inFile,"r")
  124. output=fs.open(outFile,"w")
  125.     while true do -- The primary loop of which the prgoram is compiled in
  126.         line = inFile.readLine() -- This reads the line
  127.         translate(line)
  128.         if (not line) then inFile.close() outFile.close() os.reboot() break end -- This checks and makes it stop when there is a blank line    
  129.     end
  130. end
  131. function intro() -- Introduction function.
  132.  
  133.  clear()
  134.     printLogo()
  135.         print("Welcome to the RypScript transalter.")
  136.         print("Enter the path to the file to translate from:")
  137.         inPath=read()
  138.             print("Enter the path to the file to output too:")
  139.             outPath=read()
  140.             readFile(inPath,outPath)
  141. end
  142. intro()
Advertisement
Add Comment
Please, Sign In to add comment