-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.c
More file actions
48 lines (39 loc) · 946 Bytes
/
main.c
File metadata and controls
48 lines (39 loc) · 946 Bytes
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
/**
* Assembler for systems programming course.
* by Sami Dadon and Itamar Bar-Lev.
*/
#include "error.h"
#include "parser.h"
#include "reader.h"
#include "translator.h"
#include <stdlib.h>
/*
* Main is responsible for initiating the file reading and parsing.
*/
int main(int argc, char* argv[]) {
int success;
if (argc < 2)
error_fatal(ErrorMissingArgument);
/* Open and read files. */
for (; argc > 1; argc--) {
reader_open_file(argv[argc - 1]);
/* Build the data. */
success = parse();
reader_close_file();
if (!success) {
printf("Errors found, skipping translation.\n");
parser_clean();
continue;
}
printf("Parsing finished successfully.\n");
/* Perform "Second iteration". */
success = translate();
if (success)
printf("File assembled successfully.\n");
else
printf("Errors encountered in the translation phase.\n");
/* Clean data. */
parser_clean();
}
return EXIT_SUCCESS;
}