-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
36 lines (29 loc) · 919 Bytes
/
main.lua
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
-- main.lua
-- require('lox/scanner')
require('lox/Lox')
-- Starts up the Lox interpreter to get things rolling.
-- Lox:main()
local input
local scan
local parser
local interpreter = Interpreter:new()
repeat
io.write("> ") -- io.write, writes that thing to the buffer
io.flush() -- flushes the buffer
input=io.read() -- reads the input, or receives it on enter.
scan = Scanner:new(input)
scan:scanTokens()
scan:spitTokens()
parser = Parser:new(scan.tokens)
interpreter:interpret(parser:parse())
until input == "exit"
-- It's possible to write a REPL if you just do something wiht the input, and scann it, and lex it, then load the code, then execute the code. I think.
-- local pipe = io.popen(stdout)
-- repeat
-- local c = pipe:read(1)
-- if c == 'stop' then
-- -- Do something with the char received
-- io.write(c) io.flush()
-- end
-- until not c
-- pipe:close()