-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdriver.c
executable file
·114 lines (104 loc) · 3.45 KB
/
driver.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
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
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Group no. 50
* Aniruddha Mahajan -------- 2017A7PS0145P
* Ravindra Singh Shekhawat - 2017A7PS0146P
* Shreyas Srikrishna ------- 2017A7PS0162P
* Chetan Sharma ------------ 2017A7PS0182P
*/
#include "lexer.h"
#include "parser.h"
#include <time.h>
#include "ast.h"
#include "symboltable.h"
#include "semantic.h"
#include "codeGeneration.h"
#include "offsetComputer.h"
int main (int argc,char **argv)
{
char arr[20] = "out.txt";
int option;
clock_t begin, end;
double total_CPU_time,total_CPU_time_in_seconds;
//printf("%s %s %s", argv[0], argv[1], argv[2]);
while(1){
printf("Please Select Option\n");
printf("***********************\n");
printf("1. Press 1 to test lexer. \n");
printf("2. Press 2 to print parse tree. \n");
printf("3. Press 3 to Print Abstract Syntax Tree (AST). \n");
printf("4. Press 4 to Find Compression Ratio. \n");
printf("5. Press 5 to Print Symbol Table. \n");
printf("6. Press 6 to Print Activation Record Size. \n");
printf("7. Press 7 to Print Static and Dynamic Arrays.\n");
printf("8. Press 8 to Check Errors and Total Compilation Time. \n");
printf("9. Press 9 for Assembly Code Generation. \n");
printf("10.Press 0 for Exit.\n");
printf("\n");
scanf("%d", &option);
switch(option){
case 0: printf("Exiting!\n");
return 0;
case 1: testLexer(argv[1]);
return 0;
case 2: testParseTree(argv[1], arr);
return 0;
case 3: {
testAST(argv[1],arr);
ASTNode* root = getAST();
printAST(root);
return 0;
}
case 4: {
testAST(argv[1],arr);
int parseNode = getParseTreeNode();
int astNodes = getAstNodes();
printf("Parse Tree Nodes: %d Memory Used in Parse tree: %ld\n",parseNode,parseNode*sizeof(ParseTreeNode));
printf("Abstract Syntax Tree Nodes: %d Memory used in AST: %ld\n",astNodes,parseNode*sizeof(ASTNode));
int compressionR = getCompressionRatio();
printf("Compression Ratio: %d\n",compressionR);
return 0;
}
case 5: {
testAST(argv[1],arr);
semanticAnalyzer();
SymbolTable* s = getsymbolTable();
printf("variable_name scope(module_name) scope(line_numbers) width isArray static_or_dynamic range_lexemes type_of_element offset nesting_level\n");
printSymbolTable(s);
return 0;
}
case 6: {
testAST(argv[1],arr);
semanticAnalyzer();
SymbolTable* s = getsymbolTable();
printActivationRecord(s);
return 0;
}
case 7: {
testAST(argv[1],arr);
semanticAnalyzer();
SymbolTable* s = getsymbolTable();
printArrays(s);
return 0;
}
case 8:{begin =clock();
//double total_CPU_time, total_CPU_time_in_seconds;
testAST(argv[1],arr);
semanticAnalyzer();
ListOfErrors* error = getSemanticErrorObject();
printErrors(error);
end = clock();
total_CPU_time = (double) (end - begin);
total_CPU_time_in_seconds = total_CPU_time / CLOCKS_PER_SEC;
printf("\n\n total_CPU_time = %f Total_CPU_time_in_seconds = %f\n\n",total_CPU_time,total_CPU_time_in_seconds);
return 0;
}
case 9:{
testAST(argv[1], arr);
semanticAnalyzer();
codeGenControl(getAST(), getsymbolTable(), argv[2]);
return 0;
}
}
}
return 0;
}