...
This commit is contained in:
47
compiler/Program.cs
Normal file
47
compiler/Program.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Compiler;
|
||||
|
||||
const string fileName = "test.nub";
|
||||
|
||||
var file = File.ReadAllText(fileName);
|
||||
|
||||
var tokens = Tokenizer.Tokenize(fileName, file, out var tokenizerDiagnostics);
|
||||
|
||||
foreach (var diagnostic in tokenizerDiagnostics)
|
||||
{
|
||||
DiagnosticFormatter.Print(diagnostic, Console.Error);
|
||||
}
|
||||
|
||||
if (tokenizerDiagnostics.Any(x => x.Severity == DiagnosticSeverity.Error))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var ast = Parser.Parse(fileName, tokens, out var parserDiagnostics);
|
||||
|
||||
foreach (var diagnostic in parserDiagnostics)
|
||||
{
|
||||
DiagnosticFormatter.Print(diagnostic, Console.Error);
|
||||
}
|
||||
|
||||
if (parserDiagnostics.Any(x => x.Severity == DiagnosticSeverity.Error))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var typedAst = TypeChecker.Check(fileName, ast, out var typeCheckerDiagnostics);
|
||||
|
||||
foreach (var diagnostic in typeCheckerDiagnostics)
|
||||
{
|
||||
DiagnosticFormatter.Print(diagnostic, Console.Error);
|
||||
}
|
||||
|
||||
if (typeCheckerDiagnostics.Any(x => x.Severity == DiagnosticSeverity.Error))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
var output = Generator.Emit(typedAst);
|
||||
|
||||
File.WriteAllText("C:/Users/oliste/repos/nub-lang/compiler/Compiler/out.c", output);
|
||||
|
||||
return 0;
|
||||
Reference in New Issue
Block a user