/
Driver.d
48 lines (46 loc) · 1.37 KB
/
Driver.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import std.stdio : writeln, stderr;
import std.conv : to;
import std.exception : collectExceptionMsg;
import LexerImpl : LexerImpl;
import Parser : Parser;
import SymbolTable : SymbolTable, Edition;
import Node : Node;
immutable uint MAX_SUPPORTED_EDITION = 4;
int main(const string[] args) {
uint edition = MAX_SUPPORTED_EDITION;
if (args.length == 2) {
edition = to!uint(args[1]);
if ((edition < 1) || (edition > 6)) {
stderr.writeln("Bad edition (must be 1-6)");
return 1;
}
}
auto symtab = new SymbolTable(cast(Edition)edition);
auto lexer = new LexerImpl(symtab);
stderr.writeln("BASIC The ", to!string(symtab.edition),
symtab.edition > MAX_SUPPORTED_EDITION ? " (not yet implemented)" : "");
auto head = new Node(symtab);
auto parser = new Parser(lexer, symtab, head);
auto msg = collectExceptionMsg(parser.parse());
if (msg) {
symtab.error(msg);
}
else if (!symtab.end && !symtab.errors) {
symtab.error("MISSING END");
}
if (!symtab.errors) {
auto generate = {
head.prolog();
symtab.codegen();
head.codegen();
head.epilog();
};
msg = collectExceptionMsg(generate());
if (msg) {
symtab.error(msg);
return 1;
}
return 0;
}
return 1;
}