Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. S = io.read()
  2. S=S:gsub("%s+","")
  3. S=S:gsub("[^-+*/^()]+","v(\"%1\")")
  4.  
  5. S=S:gsub("([^)])%+v","%1~v")
  6. S=S:gsub("^%+v","~v")
  7. mt={}
  8. function mt.__add(a,b)
  9.     local u={cpf=a.cpf.." "..b.cpf.." +"}
  10.     setmetatable (u, mt)
  11.     return u
  12. end
  13.  
  14. function mt.__sub(a,b)
  15.     local u={cpf=a.cpf.." "..b.cpf.." -"}
  16.     setmetatable (u, mt)
  17.     return u
  18. end
  19.  
  20. function mt.__mul(a,b)
  21.     local u={cpf=a.cpf.." "..b.cpf.." *"}
  22.     setmetatable (u, mt)
  23.     return u
  24. end
  25.  
  26. function mt.__div(a,b)
  27.     local u={cpf=a.cpf.." "..b.cpf.." /"}
  28.     setmetatable (u, mt)
  29.     return u
  30. end
  31.  
  32. function mt.__pow(a,b)
  33.     local u={cpf=a.cpf.." "..b.cpf.." ^"}
  34.     setmetatable (u, mt)
  35.     return u
  36. end
  37.  
  38. function mt.__unm(a)
  39.     local u={cpf=a.cpf.." @-"}
  40.     setmetatable (u, mt)
  41.     return u
  42. end
  43.  
  44. function mt.__bnot(a)
  45.     local u={cpf=a.cpf.." @+"}
  46.     setmetatable (u, mt)
  47.     return u
  48. end
  49.  
  50. function v(x)
  51.     local u={cpf=x}
  52.     setmetatable (u, mt)
  53.     return u
  54. end
  55.  
  56. io.stderr:write(S.."\n")
  57.  
  58. r=load("return "..S)()
  59. print(r.cpf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement