-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
125 lines (77 loc) · 2.59 KB
/
main.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
115
116
117
118
119
120
121
122
123
#include "uti1.h"
#include "mainLab.h"
char line[MAX_LINE]; /*array to get line by line*/
int line_num=0;
char *file_name;
FILE *fd;
int main(int argc, char *argv[])
{
int i;
if(argc == 1){
printf("please enter file name");
exit(0);
}
/*printf("\n%s\n",argv[2]);*/
for(i=1; i<argc; i++) /* loop for all the files the user input */
{
file_name=(char *)malloc(strlen(argv[i])+4);
if(! file_name){
printf("\ncannot allocate memmory for file_name\n");
break;
}
/* add the suffix .as to the file name */
strcpy(file_name,argv[i]);
strcat(file_name,".as");
printf("\n%s ",file_name); /*print to check if the file name is correct V */
/* open the specific file, and if not open so rise a massage */
fd = fopen(file_name,"r");
if(!fd){
printf("\ncannot open %s file\n",file_name);
break;
}
while(! feof(fd)){ /*first transition*/
/* printf("\n%s\n",line); print to check if it reads from the file to the array line V */
analize1(line); /*first analize*/
line_num++;
fgets(line,MAX_LINE,fd); /*get one line from the file V */
}
line[0]='\0'; /*empty the first element of the array*/
rewind(fd); /*return the read pointer to the beggining of the text file for the sercond transition*/
/*zero the parameters before the next analize*/
line_num=0;
clean_line(line);
I=0;
fix_sym_add(); /*update the address of the guide labels in the symbal table*/
while(! feof(fd)){/*second transition*/
analize2(line); /*second analize*/
line_num++;
fgets(line,MAX_LINE,fd);
}
fclose(fd); /*close file*/
if(! errorC){ /*if there is no errors create the files, else- print the errors to screen*/
create_ob_file();
create_ent_file();
create_ext_file();
printf("Compiled\n");
}
else
printErrors();
/*printf("\n%c\n",data_table[0]->address);*/
/*print_table_data(); */
/*print_labels(sym); /*print the labels names*/
D=0; /*zero the data table i*/
I=0; /*zero the inst table i*/
DC=0; /*zero the data counter*/
IC=100; /*zero to 100 the instruction counter*/
line_num=0;
clean_line(line); /*clean the line array*/
free(file_name); /*free the file name parameter*/
freeError(); /*free the error table*/
free_table_data(); /*free all the data table*/
free_table_op(); /*free operation table list*/
free_symList(); /*free all the allocated nodes of the symball list*/
free_entList();/*free entry list*/
free_extList();/*free external list*/
}/*end of for loop to open the files which givven from CMD by their names*/
return 0;
} /*End of Main*/