51 lines
1.1 KiB
Modula-2
51 lines
1.1 KiB
Modula-2
MODULE Compiler;
|
|
|
|
FROM FIO IMPORT Close, IsNoError, File, OpenToRead, StdErr, StdOut, WriteLine, WriteString;
|
|
FROM SYSTEM IMPORT ADR;
|
|
FROM M2RTS IMPORT HALT, ExitOnHalt;
|
|
|
|
FROM Lexer IMPORT Lexer, lexer_destroy, lexer_initialize;
|
|
FROM Transpiler IMPORT transpile;
|
|
FROM CommandLineInterface IMPORT PCommandLine, parse_command_line;
|
|
|
|
VAR
|
|
command_line: PCommandLine;
|
|
|
|
PROCEDURE compile_from_stream();
|
|
VAR
|
|
lexer: Lexer;
|
|
source_input: File;
|
|
BEGIN
|
|
source_input := OpenToRead(command_line^.input);
|
|
|
|
IF IsNoError(source_input) = FALSE THEN
|
|
WriteString(StdErr, 'Fatal error: failed to read the input file "');
|
|
WriteString(StdErr, command_line^.input);
|
|
WriteString(StdErr, '".');
|
|
WriteLine(StdErr);
|
|
|
|
ExitOnHalt(2)
|
|
END;
|
|
IF IsNoError(source_input) THEN
|
|
lexer_initialize(ADR(lexer), source_input);
|
|
|
|
transpile(ADR(lexer), StdOut);
|
|
|
|
lexer_destroy(ADR(lexer));
|
|
|
|
Close(source_input)
|
|
END
|
|
END compile_from_stream;
|
|
BEGIN
|
|
ExitOnHalt(0);
|
|
command_line := parse_command_line();
|
|
|
|
IF command_line <> NIL THEN
|
|
compile_from_stream()
|
|
END;
|
|
IF command_line = NIL THEN
|
|
ExitOnHalt(1)
|
|
END;
|
|
HALT()
|
|
END Compiler.
|