-
Notifications
You must be signed in to change notification settings - Fork 0
/
MimaC.cs
80 lines (69 loc) · 2.75 KB
/
MimaC.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using mima_c.ast;
using mima_c.compiler;
using System;
using System.IO;
using System.Linq;
namespace mima_c
{
class MimaC
{
static void Main(string[] args)
{
bool showOuput = !args.Contains("--no_debug");
string file;
if (args.Contains("--file"))
file = args[Array.IndexOf(args, "--file") + 1];
else
file = "../../../src/test.c";
string inputText = File.ReadAllText(file);
string preprozessedText = new PreProzessor(inputText).GetProcessedText();
if (showOuput)
{
Console.WriteLine("Preprozessing Done");
Console.WriteLine(preprozessedText);
}
TokenStream tokenStream = new Lexer(preprozessedText).GetTokenStream();
if (showOuput)
Console.WriteLine("Lexing Done");
Program ast = new CParser(tokenStream).Parse();
if (showOuput)
{
Console.WriteLine("Parsing Done");
Console.WriteLine("--------------------- :AST: ---------------------");
Console.WriteLine(ast.ToString());
Console.WriteLine("-------------------------------------------------");
}
// int result = new interpreter.Interpreter(ast).Interpret();
// if (showOuput)
// {
// Console.WriteLine();
// Console.WriteLine("Interpreting Done");
// Console.WriteLine("Result: " + result.ToString());
// }
PreCompiler.PreCompiledAST preCompiled = new PreCompiler().PreComile(ast);
if (showOuput)
{
Console.WriteLine("Pre Compilation Done");
Console.WriteLine("--------------------- :AST: ---------------------");
Console.WriteLine(preCompiled.Program.ToString());
Console.WriteLine("------------------ :FUNCTIONS: ------------------");
foreach (var func in preCompiled.Functions)
Console.WriteLine(func.ToString());
Console.WriteLine("-------------------------------------------------");
}
Compiler.Runnable compiled = new Compiler("output.mima").Compile(preCompiled);
if (showOuput)
Console.WriteLine("Compilation Done");
if (compiled == null)
Environment.Exit(1);
int result = compiled.Run();
if (showOuput)
{
Console.WriteLine();
Console.WriteLine("Running Done");
Console.WriteLine("Result: " + result.ToString());
}
Environment.Exit(result);
}
}
}