-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
50 lines (41 loc) · 1.31 KB
/
Program.cs
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
using System;
using System.Globalization;
using System.Threading;
using Antlr4.Runtime;
using Dust.Compiler;
using Dust.Language;
using Dust.Language.Errors;
using Dust.Language.Nodes;
namespace Dust.CLI
{
public static class Program
{
private static void Main(string[] args)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
DustContext context = new DustContext();
DustRuntimeCompiler compiler = new DustRuntimeCompiler(context);
string input;
while ((input = Console.ReadLine()) != "exit")
{
AntlrInputStream inputStream = new AntlrInputStream(input);
DustLexer lexer = new DustLexer(inputStream);
CommonTokenStream commonTokenStream = new CommonTokenStream(lexer);
DustParser parser = new DustParser(commonTokenStream);
DustVisitor visitor = new DustVisitor(context);
Module module = (Module) visitor.VisitModule(parser.module());
object result = compiler.Compile(module).Value;
bool hasErrored = false;
foreach (Error error in context.ErrorHandler.Errors)
{
hasErrored = true;
Console.WriteLine(error);
}
if (result != null && hasErrored == false)
{
Console.WriteLine(result);
}
}
}
}
}