-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.jl
72 lines (61 loc) · 1.32 KB
/
main.jl
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
include("./token.jl")
include("./scanner.jl")
include("./parser.jl")
include("./interpreter.jl")
include("./expressions.jl")
include("./errors.jl")
include("./debug.jl")
include("./resolver.jl")
function main()
if length(ARGS) > 1
println("Usage: jlox [script]");
System.exit(64);
elseif length(ARGS) == 1
runFile(ARGS[])
else
runPrompt()
end
end
function runFile(path)
# println("Running file ", path, "...")
open(path, "r") do f
data = read(f, String)
run(data)
end
end
function runPrompt()
while true
print("> ")
line = readline()
if line == ""
continue
end
run(line)
print("\n")
end
end
function run(source::String)
tokens = scanTokens(source);
# for t in tokens
# println(t)
# end
q("==>> Stage 1: Parse <<==")
statements = parseTokens(tokens)
# TODO:
# if (hadError) return;
for s in statements
q(s)
end
q("==>> Stage 2: Resolve <<==")
locals, resolveError = resolveStatements(statements)
q(locals)
if resolveError
return
end
# print(expr)
q("==>> Stage 3: Interpret <<==")
interpret(statements, locals)
# TODO: AstPrinter
# System.out.println(new AstPrinter().print(expression));
end
main()