Create a parser context
This commit is contained in:
@ -1,13 +1,15 @@
|
||||
MODULE Compiler;
|
||||
|
||||
FROM FIO IMPORT Close, IsNoError, File, OpenToRead, StdErr, StdOut, WriteLine, WriteString;
|
||||
FROM FIO IMPORT Close, IsNoError, File, OpenToRead, OpenToWrite, StdErr, StdOut, WriteLine, WriteString;
|
||||
FROM SYSTEM IMPORT ADR;
|
||||
FROM M2RTS IMPORT HALT, ExitOnHalt;
|
||||
|
||||
FROM Lexer IMPORT Lexer, lexer_destroy, lexer_initialize;
|
||||
FROM Parser IMPORT Parser;
|
||||
FROM Transpiler IMPORT transpile;
|
||||
FROM CommandLineInterface IMPORT PCommandLine, parse_command_line;
|
||||
FROM Parser IMPORT PAstModule, parse_module;
|
||||
FROM Parser IMPORT PAstModule, parse;
|
||||
FROM Strings IMPORT Length;
|
||||
|
||||
VAR
|
||||
command_line: PCommandLine;
|
||||
@ -16,6 +18,7 @@ PROCEDURE compile_from_stream();
|
||||
VAR
|
||||
lexer: Lexer;
|
||||
source_input: File;
|
||||
source_output: File;
|
||||
ast_module: PAstModule;
|
||||
BEGIN
|
||||
source_input := OpenToRead(command_line^.input);
|
||||
@ -28,14 +31,30 @@ BEGIN
|
||||
|
||||
ExitOnHalt(2)
|
||||
END;
|
||||
source_output := NIL;
|
||||
|
||||
IF Length(command_line^.output) > 0 THEN
|
||||
source_output := OpenToWrite(command_line^.output);
|
||||
|
||||
IF IsNoError(source_output) = FALSE THEN
|
||||
WriteString(StdErr, 'Fatal error: failed to create the output file "');
|
||||
WriteString(StdErr, command_line^.output);
|
||||
WriteString(StdErr, '".');
|
||||
WriteLine(StdErr);
|
||||
|
||||
ExitOnHalt(2)
|
||||
END
|
||||
END;
|
||||
|
||||
IF IsNoError(source_input) THEN
|
||||
lexer_initialize(ADR(lexer), source_input);
|
||||
|
||||
ast_module := parse_module(ADR(lexer));
|
||||
transpile(ast_module, StdOut, command_line^.input);
|
||||
ast_module := parse(ADR(lexer));
|
||||
transpile(ast_module, StdOut, source_output, command_line^.input);
|
||||
|
||||
lexer_destroy(ADR(lexer));
|
||||
|
||||
Close(source_output);
|
||||
Close(source_input)
|
||||
END
|
||||
END compile_from_stream;
|
||||
|
Reference in New Issue
Block a user