Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vars= {}
- 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] == '"' or s[i] == "'" then
- if textS == false then textS= true tS= true
- elseif textS == true then textS= false tS= false end
- 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
- token= {}
- specWords= {'for'}
- forS= false
- forSS= false
- for i=1,#tokens do
- token[i]= {}
- forS= false
- forSS= false
- d= tonumber(tokens[i])
- if (type(d) == 'number') then
- token[i][1]= 'number'
- token[i][2]= d
- forSS= true
- end
- for q=1,#specT do
- if (tokens[i] == specT[q]) then
- token[i][1]= 'SS'
- token[i][2]= tokens[i]
- forS= true
- break
- end
- end
- if (forS == false) then
- for q=1,#specWords do
- if (tokens[i] == specWords[q]) then
- token[i][1]= 'SW'
- token[i][2]= tokens[i]
- forSS= true
- break
- end
- end
- if (forSS == false) then
- token[i][1]= 'word'
- token[i][2]= tokens[i]
- end
- end
- end
- for i=1,#token do
- print(token[i][1],' ',token[i][2])
- end
- return token
- end
- while true do
- io.write('Line<')
- mess= io.read()
- if (mess == 'ex') then break end
- s= parse(mess)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement