diff --git a/source/CommandLine.def b/source/CommandLine.def new file mode 100644 index 0000000..37fd7fa --- /dev/null +++ b/source/CommandLine.def @@ -0,0 +1,3 @@ +DEFINITION MODULE CommandLine; + +END CommandLine. diff --git a/source/CommandLine.mod b/source/CommandLine.mod new file mode 100644 index 0000000..215f7c3 --- /dev/null +++ b/source/CommandLine.mod @@ -0,0 +1,3 @@ +MODULE CommandLine; + +END CommandLine. diff --git a/source/CommandLineInterface.def b/source/CommandLineInterface.def new file mode 100644 index 0000000..85be324 --- /dev/null +++ b/source/CommandLineInterface.def @@ -0,0 +1,15 @@ +DEFINITION MODULE CommandLineInterface; + +FROM Common IMPORT ShortString; + +TYPE + CommandLine = RECORD + input: ShortString; + lex: BOOLEAN; + parse: BOOLEAN + END; + PCommandLine = POINTER TO CommandLine; + +PROCEDURE parse_command_line(): PCommandLine; + +END CommandLineInterface. diff --git a/source/CommandLineInterface.mod b/source/CommandLineInterface.mod new file mode 100644 index 0000000..2b33668 --- /dev/null +++ b/source/CommandLineInterface.mod @@ -0,0 +1,74 @@ +IMPLEMENTATION MODULE CommandLineInterface; + +FROM SYSTEM IMPORT ADR, TSIZE; + +FROM Args IMPORT GetArg, Narg; +FROM FIO IMPORT WriteString, WriteChar, WriteLine, StdErr; +FROM Storage IMPORT ALLOCATE; +FROM Strings IMPORT CompareStr, Length; +FROM MemUtils IMPORT MemZero; + +FROM Common IMPORT ShortString; + +PROCEDURE parse_command_line(): PCommandLine; +VAR + parameter: ShortString; + i: CARDINAL; + result: PCommandLine; + parsed: BOOLEAN; +BEGIN + i := 1; + ALLOCATE(result, TSIZE(CommandLine)); + result^.lex := FALSE; + result^.parse := FALSE; + MemZero(ADR(result^.input), 256); + + WHILE (i < Narg()) AND (result <> NIL) DO + parsed := GetArg(parameter, i); + parsed := FALSE; + + IF CompareStr(parameter, '--lex') = 0 THEN + parsed := TRUE; + result^.lex := TRUE + END; + IF CompareStr(parameter, '--parse') = 0 THEN + parsed := TRUE; + result^.parse := TRUE + END; + IF parameter[0] <> '-' THEN + parsed := TRUE; + + IF Length(result^.input) > 0 THEN + WriteString(StdErr, 'Fatal error: only one source file can be compiled at once. First given "'); + WriteString(StdErr, result^.input); + WriteString(StdErr, '", then "'); + WriteString(StdErr, parameter); + WriteString(StdErr, '".'); + WriteLine(StdErr); + result := NIL + END; + IF result <> NIL THEN + result^.input := parameter + END + END; + IF parsed = FALSE THEN + WriteString(StdErr, 'Fatal error: unknown command line options: '); + + WriteString(StdErr, parameter); + WriteChar(StdErr, '.'); + WriteLine(StdErr); + + result := NIL + END; + + i := i + 1 + END; + IF (result <> NIL) AND (Length(result^.input) = 0) THEN + WriteString(StdErr, 'Fatal error: no input files.'); + WriteLine(StdErr); + result := NIL + END; + + RETURN result +END parse_command_line; +END CommandLineInterface. diff --git a/source/Common.def b/source/Common.def new file mode 100644 index 0000000..5925cbf --- /dev/null +++ b/source/Common.def @@ -0,0 +1,6 @@ +DEFINITION MODULE Common; + +TYPE + ShortString = ARRAY[0..255] OF CHAR; + +END Common. diff --git a/source/Common.mod b/source/Common.mod new file mode 100644 index 0000000..135d3a9 --- /dev/null +++ b/source/Common.mod @@ -0,0 +1,3 @@ +IMPLEMENTATION MODULE Common; + +END Common. diff --git a/source/Compiler.mod b/source/Compiler.mod index c6b3e09..9e2ed04 100644 --- a/source/Compiler.mod +++ b/source/Compiler.mod @@ -5,11 +5,15 @@ FROM SYSTEM IMPORT ADR; FROM Lexer IMPORT Lexer, lexer_destroy, lexer_initialize; FROM Transpiler IMPORT transpile; +FROM CommandLineInterface IMPORT PCommandLine, parse_command_line; VAR lexer: Lexer; + command_line: PCommandLine; BEGIN + command_line := parse_command_line(); + lexer_initialize(ADR(lexer), StdIn); transpile(ADR(lexer)); diff --git a/source/Parser.def b/source/Parser.def new file mode 100644 index 0000000..5b016de --- /dev/null +++ b/source/Parser.def @@ -0,0 +1,3 @@ +DEFINITION MODULE Parser; + +END Parser. diff --git a/source/Parser.mod b/source/Parser.mod new file mode 100644 index 0000000..bf39cc7 --- /dev/null +++ b/source/Parser.mod @@ -0,0 +1,3 @@ +MODULE Parser; + +END Parser. diff --git a/source/Transpiler.mod b/source/Transpiler.mod index 63ce824..e5c0317 100644 --- a/source/Transpiler.mod +++ b/source/Transpiler.mod @@ -421,6 +421,14 @@ BEGIN WriteString('NIL '); written_bytes := 1 END; + IF (token.kind = lexerKindBoolean) AND token.booleanKind THEN + WriteString('TRUE '); + written_bytes := 1 + END; + IF (token.kind = lexerKindBoolean) AND (~token.booleanKind) THEN + WriteString('FALSE '); + written_bytes := 1 + END; IF token.kind = lexerKindOr THEN WriteString('OR '); written_bytes := 1