forked from louisje/OpenComputer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Compiler.c
57 lines (52 loc) · 1.96 KB
/
Compiler.c
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
49
50
51
52
53
54
55
56
57
#include "Compiler.h"
/*
void compile(char *cFile, char *asmFile) { // 編譯器主程式
Compiler *c = CompilerNew();
CompilerCompile(cFile, asmFile);
CompilerFree(c);
}
Compiler *CompilerNew() {
Compiler *c = ObjNew(Compiler, 1);
c->symTable = SymTableNew();
c->scanner = ScannerNew();
c->parser = ParserNew(c->scanner, c->symTable);
c->sa = SaNew(c->symTable, c->parser);
c->gen = GenNew(c->symTable, c->parser->tree);
}
void CompilerCompile(char *cFile, char *asmFile) {
printf("compile file:%s\n", cFile, asmFile);
char *cText = fileToStr(cFile); // 讀取檔案到 cText 字串中。
debug("================ Scan =========================\n");
ScannerScan(c->scanner, cText);
debug("================ Parse ========================\n");
Tree *tree = ParserParse(c->parser, c->scanner); // 剖析程式 (cText) 轉為語法樹
freeMemory(cText);
debug("================ Semantic Analysis ============\n");
semanticAnalysis(tree, symTable);
TreePrintLevel(tree, 0);
debug("================ Code Generator ===============\n");
}
void CompilerFree(Compiler *c) {
ParserFree(c->parser);
SaFree(c->sa);
GenFree(c->generator);
}
*/
void compile(char *cFile, char *asmFile) { // 編譯器主程式
printf("compile file:%s\n", cFile, asmFile);
char *cText = fileToStr(cFile); // 讀取檔案到 cText 字串中。
SymTable *symTable = SymTableNew();
Tree *tree = parse(cText, symTable); // 剖析程式 (cText) 轉為語法樹
ERROR();
debug("================ Semantic Tree ================\n");
semanticAnalysis(tree, symTable);
// SymTableDebug(symTable);
// ERROR();
TreePrintLevel(tree, 0);
ERROR();
// TreePrint(parser->tree);
// generate(parser->tree, symTable, asmFile); // 程式碼產生
TreeFree(tree);
freeMemory(cText);
ERROR();
}