Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- S = io.read()
- S=S:gsub("%s+","")
- S=S:gsub("[^-+*/^()]+","v(\"%1\")")
- S=S:gsub("([^)])%+v","%1~v")
- S=S:gsub("^%+v","~v")
- mt={}
- function mt.__add(a,b)
- local u={cpf=a.cpf.." "..b.cpf.." +"}
- setmetatable (u, mt)
- return u
- end
- function mt.__sub(a,b)
- local u={cpf=a.cpf.." "..b.cpf.." -"}
- setmetatable (u, mt)
- return u
- end
- function mt.__mul(a,b)
- local u={cpf=a.cpf.." "..b.cpf.." *"}
- setmetatable (u, mt)
- return u
- end
- function mt.__div(a,b)
- local u={cpf=a.cpf.." "..b.cpf.." /"}
- setmetatable (u, mt)
- return u
- end
- function mt.__pow(a,b)
- local u={cpf=a.cpf.." "..b.cpf.." ^"}
- setmetatable (u, mt)
- return u
- end
- function mt.__unm(a)
- local u={cpf=a.cpf.." @-"}
- setmetatable (u, mt)
- return u
- end
- function mt.__bnot(a)
- local u={cpf=a.cpf.." @+"}
- setmetatable (u, mt)
- return u
- end
- function v(x)
- local u={cpf=x}
- setmetatable (u, mt)
- return u
- end
- io.stderr:write(S.."\n")
- r=load("return "..S)()
- print(r.cpf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement