Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term= require('term')
- c= require('component')
- side= require('sides')
- term.clear()
- prosh_rez= ''
- rez= ''
- function drop(line)
- s= {}
- for i=1,#line do
- s[#s+1]= string.sub(line,i,i)
- end
- for i=1,#s do
- end
- return s
- end
- function tempS()
- if temp ~= '' then
- return true
- elseif temp == '' then
- return false
- end
- end
- function parse(lines)
- tokens= {}
- textS= false
- forS= false
- tS= false
- specT= {'<','>','=',',','.','(',')',':',"'",'?'}
- Numbers= {'0','1','2','3','4','5','6','7','8','9'}
- temp= ''
- i= 0
- d= 0
- line= 2
- simb= 2
- s= drop(lines)
- i= 0
- while i<#s do
- i= i+1
- forS= false
- if (string.byte(s[i]) > 48 and string.byte(s[i]) < 58) then
- if temp~= '' then
- tokens[#tokens+1]= temp
- temp= ''
- end
- c= ''
- while true do
- stat= false
- for h=1,#Numbers do
- if (Numbers[h] == s[i]) then
- c= c..s[i]
- stat= true
- end
- end
- if (stat == false) then
- tokens[#tokens+1]= c
- c= ''
- break
- end
- i= i+1
- end
- end
- if g == line and i == simb then
- --print(textS)
- end
- if s[i] == ' ' and textS == false then
- if temp ~= '' then
- tokens[#tokens+1]= temp
- end
- temp= ''
- forS= true
- while true do
- --print(i," ",s[i])
- if s[i+1] ~= ' ' then
- break
- end
- i= i+1
- end
- end
- for q=1,#specT do
- if s[i] == specT[q] and tS == false then
- forS= true
- if temp ~= "" then
- tokens[#tokens+1]= temp
- end
- tokens[#tokens+1]= s[i]
- temp= ''
- break
- end
- end
- if s[i+1] == nil then
- if tempS() then
- temp= temp..s[i]
- tokens[#tokens+1]= temp
- temp= ''
- end
- break
- end
- if forS == false then
- temp= temp..s[i]
- --print(temp)
- end
- end
- for i=1,#tokens do
- --print(i," = ",tokens[i])
- end
- return tokens
- end
- function red(siDe,length)
- c= require('component')
- l= c.list()
- for k,v in pairs(l) do
- if (v == 'redstone') then
- r= c.proxy(k)
- break
- end
- end
- if (siDe == 'right') then
- rez= r.setOutput(side.left,length+0)
- elseif (siDe == 'left') then
- rez= r.setOutput(side.right,length+0)
- end
- end
- function broadcasts(port,message)
- c= require('component')
- l= c.list()
- for k,v in pairs(l) do
- if (v == "modem") then
- q= c.proxy(k)
- break
- end
- end
- port= tonumber(port)
- q.open(port)
- rez= q.broadcast(port,message)
- q.close(port)
- end
- function S(s)
- ss= {'right','left'}
- for i=1,#ss do
- if (s == ss[i]) then return true end
- end
- return false
- end
- function isNumber(obj)
- d= tonumber(obj)
- if (type(d) == 'number') then return true end
- return false
- end
- function isString(obj)
- if (type(obj) == 'string') then return true end
- return false
- end
- function isComponents(nameC)
- c= require('component')
- l= c.list()
- for k,v in pairs(l) do
- if (v == nameC) then
- return true
- end
- end
- return false
- end
- function analyze(tokens)
- i= 0
- step= 0
- endstep= 0
- loop= 0
- count= 0
- inFor= false
- while i<#tokens do
- i= i+1
- if (tokens[i] == 'redstone' and tokens[i+1] == '.' and S(tokens[i+2]) == true and tokens[i+3] == ':' and isNumber(tokens[i+4])) then
- if (isComponents('redstone')) then
- red(tokens[i+2],tokens[i+4]+0)
- print('true')
- else
- print('false')
- end
- end
- --print(tokens[i],' ',tokens[i+1],' ',tokens[i+2],' ',tokens[i+3],' ',tokens[i+4])
- if (tokens[i] == 'redstone' and tokens[i+1] == '.' and S(tokens[i+2]) == true and tokens[i+3] == ':' and tokens[i+4] == 'close') then
- if (isComponents('redstone')) then
- red(tokens[i+2],0)
- print('true')
- else
- print('false')
- end
- end
- if (tokens[i] == 'broadcast' and tokens[i+1] == ':' and isNumber(tokens[i+2]) and tokens[i+3] == ':' and isString(tokens[i+4])) then
- if (isComponents('modem')) then
- broadcasts(tokens[i+2],tokens[i+4])
- print('true')
- else
- print('false')
- end
- end
- if (tokens[i] == 'broadcast' and tokens[i+1] == ':' and isNumber(tokens[i+2]) and tokens[i+3] == ':' and tokens[i+4] == 'rez') then
- if (isComponents('modem')) then
- if (prosh_rez ~= nil) then
- broadcasts(tokens[i+2],prosh_rez)
- print('true')
- else
- print('false')
- end
- else
- print('false')
- end
- end
- if (tokens[i] == 'broadcast' and tokens[i+1] == ':' and tokens[i+2] == 'rez' and tokens[i+3] == ':' and isString(tokens[i+4])) then
- if (isComponents('modem')) then
- if (prosh_rez ~= nil and isNumber(prosh_rez)) then
- broadcasts(prosh_rez,tokens[i+4])
- print('true')
- else
- print('false')
- end
- else
- print('false')
- end
- end
- if (tokens[i] == 'rez' and tokens[i+1] == '<' and tokens[i+2] ~= nil) then
- if (isNumber(tokens[i+2])) then
- prosh_rez= tonumber(tokens[i+2])
- print(prosh_rez)
- print('true')
- elseif (isString(tokens[i+2])) then
- prosh_rez= tokens[i+2]
- print(prosh_rez)
- print('true')
- else
- print('false')
- end
- end
- if (tokens[i] == 'pr' and tokens[i+1] == "'" and isString(tokens[i+2]) and tokens[i+3] == "'") then
- print(tokens[i+2])
- rez= true
- end
- if (tokens[i] == 'pr' and tokens[i+1] == 'rez') then
- print(rez)
- rez= true
- end
- if (tokens[i] == 'wr' and tokens[i+1] == "'" and isString(tokens[i+2]) and tokens[i+3] == "'") then
- io.write(tokens[i+2])
- rez= true
- end
- --print(i)
- if (tokens[i] == 'for' and tokens[i+1] == ':') then
- --print('yes1')
- step= i+2
- loop= tonumber(tokens[i+2])
- for q=i,#tokens do
- if (tokens[q] == '?') then
- endstep= q
- end
- end
- inFor= true
- end
- if (count<loop and i+1 == endstep and inFor == true) then
- --print('yes2')
- i= step
- count= count+1
- end
- if (count == loop and inFor == true) then
- i= endstep
- step= 0
- endstep= 0
- loop= 0
- count= 0
- inFor= false
- end
- end
- end
- while true do
- io.write("Ni >")
- mess= io.read()
- t= parse(mess)
- if (tokens[1] == 'exit') then break end
- analyze(t)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement