Wire semantic analysis pass into the compiler pipeline

The semantic analyser now runs between parsing and code generation.
Type mismatches, undeclared identifiers, and duplicate declarations are
reported to stderr with source position and exit code 1 before any IR
is emitted.
This commit is contained in:
Graeme Geldenhuys 2026-04-20 18:01:03 +01:00
parent 4fbfdfdbba
commit 8122b0a299

View file

@ -16,7 +16,7 @@ program Blaise;
uses
SysUtils, Classes, Process,
uLexer, uParser, uAST, uCodeGenQBE;
uLexer, uParser, uAST, uSemantic, uCodeGenQBE;
const
Version = '0.1.0-alpha';
@ -272,10 +272,11 @@ var
SourceFile, OutputFile: string;
EmitIR: Boolean;
Source: TStringList;
Lexer: TLexer;
Parser: TParser;
Prog: TProgram;
CG: TCodeGenQBE;
Lexer: TLexer;
Parser: TParser;
Prog: TProgram;
Semantic: TSemanticAnalyser;
CG: TCodeGenQBE;
IR: string;
IRFile: string;
@ -315,10 +316,11 @@ begin
end;
end;
Lexer := nil;
Parser := nil;
Prog := nil;
CG := nil;
Lexer := nil;
Parser := nil;
Prog := nil;
Semantic := nil;
CG := nil;
try
try
Lexer := TLexer.Create(Source.Text);
@ -332,6 +334,17 @@ begin
end;
end;
try
Semantic := TSemanticAnalyser.Create;
Semantic.Analyse(Prog);
except
on E: ESemanticError do
begin
WriteLn(StdErr, 'Semantic error: ', E.Message);
Halt(1);
end;
end;
try
CG := TCodeGenQBE.Create;
CG.Generate(Prog);
@ -345,6 +358,7 @@ begin
end;
finally
CG.Free;
Semantic.Free;
Prog.Free;
Parser.Free;
Lexer.Free;