Type checking basics
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using Compiler;
|
||||
|
||||
var file = File.ReadAllText("test.nub");
|
||||
const string fileName = "test.nub";
|
||||
|
||||
var tokens = Tokenizer.Tokenize("test.nub", file, out var tokenizerDiagnostics);
|
||||
var file = File.ReadAllText(fileName);
|
||||
|
||||
var tokens = Tokenizer.Tokenize(fileName, file, out var tokenizerDiagnostics);
|
||||
|
||||
foreach (var diagnostic in tokenizerDiagnostics)
|
||||
{
|
||||
@@ -14,7 +16,7 @@ if (tokenizerDiagnostics.Any(x => x.Severity == DiagnosticSeverity.Error))
|
||||
return 1;
|
||||
}
|
||||
|
||||
var nodes = Parser.Parse("test.nub", tokens, out var parserDiagnostics);
|
||||
var nodes = Parser.Parse(fileName, tokens, out var parserDiagnostics);
|
||||
|
||||
foreach (var diagnostic in parserDiagnostics)
|
||||
{
|
||||
@@ -26,7 +28,19 @@ if (parserDiagnostics.Any(x => x.Severity == DiagnosticSeverity.Error))
|
||||
return 1;
|
||||
}
|
||||
|
||||
var output = Generator.Emit(nodes);
|
||||
var typedNodes = TypeChecker.Check(fileName, nodes, 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(typedNodes);
|
||||
|
||||
File.WriteAllText("C:/Users/oliste/repos/nub-lang/compiler/Compiler/out.c", output);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user