-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer.lua
More file actions
46 lines (43 loc) · 1.05 KB
/
lexer.lua
File metadata and controls
46 lines (43 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local program = [[135]] --This is the program for now. Shush.
local tokens = {}
local function lex(code)
local check = 1
local endPoint = 1
local currentToken = ""
while #code >= endPoint do
local dataTypa
local charac = string.sub(code, endPoint, endPoint)
if charac == " " then
if type(tonumber(currentToken)) == "number" then
currentToken = currentToken.."n"
dataTypa = "number"
else
dataTypa = "id"
end
table.insert(tokens, {dataTypa,currentToken})
currentToken = ""
else
currentToken = currentToken..charac
end
endPoint = endPoint + 1
end
if type(tonumber(currentToken)) == "number" then
currentToken = currentToken.."n"
dataTypa = "number"
else
dataTypa = "id"
end
table.insert(tokens, {dataTypa,currentToken})
while check < #code do
for i, v in pairs(tokens) do
if v[2] == " " then
table.remove(tokens, i)
end
end
check = check + 1
end
end
lex(program)
for i, v in pairs(tokens) do
print(tostring(i)..": "..v[1])
end