-
Notifications
You must be signed in to change notification settings - Fork 0
/
Executor.cs
33 lines (31 loc) · 1.29 KB
/
Executor.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
namespace YuchikiML {
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
using Sprache;
class Executor {
public static void Execute(SourceFile sourceFile) {
var preprocessed = Preprocessor.ProcessDirective(sourceFile);
Logger.LogInfo("preprocessed");
var commentLess = CommentProcessor.DeleteComments(preprocessed);
Logger.LogInfo("comment processed");
var program = ExprParser.MainParser.Parse(commentLess);
Logger.LogInfo("parsed");
CheckUndefinedVar(program);
Logger.LogInfo("varable checked");
Logger.LogInfo("ready to execute");
var value = program.Calculate();
Logger.LogInfo($"Program Ended with return value: {value}");
}
public static void CheckUndefinedVar(Expr program) {
try {
UndefinedVariableChecker.Check(program);
} catch (VariableUndefinedException ex) {
Logger.LogError($"undefined variable {ex.Variable} detected in");
ex.PartialExpressions.Select(x => x + "\n---------------------------------------------").ToList().ForEach(Logger.LogError);
Environment.Exit(1);
}
}
}
}