-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParser.lua
More file actions
104 lines (98 loc) · 3.33 KB
/
Parser.lua
File metadata and controls
104 lines (98 loc) · 3.33 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function IBScript.Parser(tokens)
local parsedTokens = {}
for _, token in ipairs(tokens) do
table.insert(parsedTokens, IBScript.Parse(token));
end
return parsedTokens;
end
function IBScript.Parse(token)
local statement = {}
local first = {
["variable:"] = function ()
statement["action"] = "assign";
statement["name"] = token[2];
statement["value"] = token[4];
end,
["func:"] = function ()
statement["action"] = "function";
statement["name"] = token[2];
statement["length"] = token[3];
end,
["call:"] = function ()
statement["action"] = "callFunction";
statement["name"] = token[2];
end,
["if:"] = function ()
statement["action"] = "if";
statement["bool"] = token[2];
statement["stateTrue"] = token[3];
statement["stateFalse"] = token[4];
end,
["stop:"] = function ()
statement["action"] = "stop";
end,
["return:"] = function ()
statement["action"] = "return";
end,
["print:"] = function ()
statement["action"] = "print";
statement["value"] = token[2];
end
}
local second = {
["=="] = function ()
statement["action"] = "equals";
statement["firstVariable"] = token[1];
statement["secondVariable"] = token[3];
statement["outputVariable"] = token[4];
end,
[">"] = function ()
statement["action"] = "more";
statement["firstVariable"] = token[1];
statement["secondVariable"] = token[3];
statement["outputVariable"] = token[4];
end,
["<"] = function ()
statement["action"] = "less";
statement["firstVariable"] = token[1];
statement["secondVariable"] = token[3];
statement["outputVariable"] = token[4];
end,
["+"] = function ()
statement["action"] = "plus";
statement["firstVariable"] = token[1];
statement["secondVariable"] = token[3];
statement["outputVariable"] = token[4];
end,
["-"] = function ()
statement["action"] = "minus";
statement["firstVariable"] = token[1];
statement["secondVariable"] = token[3];
statement["outputVariable"] = token[4];
end,
["*"] = function ()
statement["action"] = "multiplication";
statement["firstVariable"] = token[1];
statement["secondVariable"] = token[3];
statement["outputVariable"] = token[4];
end,
["/"] = function ()
statement["action"] = "division";
statement["firstVariable"] = token[1];
statement["secondVariable"] = token[3];
statement["outputVariable"] = token[4];
end,
[".."] = function ()
statement["action"] = "textManipulation";
statement["firstVariable"] = token[1];
statement["secondVariable"] = token[3];
statement["outputVariable"] = token[4];
end
}
if first[token[1]] then
first[token[1]]();
elseif second[token[2]] then
second[token[2]]();
end
return statement;
end