-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.lua
More file actions
28 lines (26 loc) · 759 Bytes
/
repl.lua
File metadata and controls
28 lines (26 loc) · 759 Bytes
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
PROMPT = ">>"
require("lexer")
require("parser")
require("eval")
local function main()
local env = Environment {}
while true do
print(PROMPT)
local input = io.read()
local lexer = Lexer { input = input }
local parser = Parser { lexer = lexer }
local program = parser:parseProgram()
if #parser:getErrors() > 0 then
print("Whoops! we ran into some monkey business here")
print("parser errors:")
ForEach(parser:getErrors(), function(error)
print(string.format("\t%s", error))
end)
end
local evaluated = Eval(program, env)
if evaluated ~= nil then
print(tostring(evaluated))
end
end
end
main()