Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
102 lines (94 loc) · 3.03 KB
/
Copy pathmain.cpp
File metadata and controls
102 lines (94 loc) · 3.03 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "scanType.h"
#include "symbolTable.h"
#include "semantic.h"
#include "yyerror.h"
#include <stdio.h>
#include <string.h>
#include <string>
extern TreeNode *tree;
extern int yyparse();
extern FILE *yyin;
FILE *code;
extern int yydebug;
extern int numErrors;
extern int warningCount;
int main(int argc, char *argv[])
{
int i;
bool printAST = false;
bool printASTAnnotated = false;
bool symTabDebug = false;
bool printMemory = false;
initErrorProcessing();
if (argc > 1)
{
if (argc >= 2)
{
for (i = 0; i < argc; i++)
{
if (strcmp(argv[i], "-d") == 0)
{
yydebug = 1;
}
else if (strcmp(argv[i], "-D") == 0)
{
symTabDebug = true;
}
else if (strcmp(argv[i], "-h") == 0)
{
printf("usage: -c [options] [sourcefile]\n");
printf("options:\n");
printf("-d - turn on parser debugging\n");
printf("-D - turn on symbol table debugging\n");
printf("-h - print this usage message\n");
printf("-p - print the abstract syntax tree\n");
printf("-P - print the abstract syntax tree plus type information\n");
printf("-M - print the abstract syntax tree plus memory information\n");
return 0;
}
else if (strcmp(argv[i], "-p") == 0)
{
printAST = true;
}
else if (strcmp(argv[i], "-P") == 0)
{
printASTAnnotated = true;
printAST = true;
}
else if (strcmp(argv[i], "-M") == 0)
{
printMemory = true;
printASTAnnotated = true;
printAST = true;
}
}
}
if ((yyin = fopen(argv[argc - 1], "r")))
{
yyparse();
if (numErrors == 0)
{
semanticAnalysis(tree, symTabDebug);
if (numErrors == 0)
{
if (printAST)
printTree(tree, 0, printASTAnnotated, printMemory);
char *filename = strdup(argv[argc - 1]);
filename[strlen(argv[argc - 1]) - 2] = 't';
filename[strlen(argv[argc - 1]) - 1] = 'm';
code = fopen(filename, "w");
code_generation(tree);
}
}
}
else
{
// fail
printf("ERROR(ARGLIST): source file \"%s\" could not be opened.\n", argv[argc - 1]);
numErrors++;
}
}
printf("Number of warnings: %d\n", warningCount);
printf("Number of errors: %d\n", numErrors);
return 0;
}