This repository was archived by the owner on Jul 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
64 lines (49 loc) · 1.78 KB
/
main.c
File metadata and controls
64 lines (49 loc) · 1.78 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
#include <stdio.h>
#include "token.h"
#include "code_generator.h"
int main(int argc, char **argv)
{
FILE *inp, *outp;
/**********************************/
/* Parse Command Line Arguments */
/**********************************/
if(argc != 3)
{
fprintf(stderr, "Usage: ./code_generator.out (pl0_lexer_out) (cg_output_file)\n");
fprintf(stderr, "\n pl0_lexer_out: The path to the file containing the lexer out for the programming language PL/0.\n");
fprintf(stderr, "\n cg_output_file: The path to the file to write the code generator output, which could contain either PM/0 assembly code or code generator error message.\n");
return -1;
}
// open the input file for reading
if( !(inp = fopen(argv[1], "r")) )
{
fprintf(stderr, "Could not open \"%s\"\n", argv[1]);
return -1;
}
// open the output file for writing
if( !(outp = fopen(argv[2], "w")) )
{
fprintf(stderr, "Could not open \"%s\"\n", argv[2]);
// Before terminating, close the input file
fclose(inp);
return -1;
}
/**********************************/
/**** Call to code generator ****/
/**********************************/
// Read the token list
TokenList tokenList = readTokenList(inp);
// Run code generator
int err = codeGenerator(tokenList, outp);
// Print error - if there exists any
if(err) printCGErr(err, outp);
// Delete token list created by readTokenList()
deleteTokenList(&tokenList);
/**********************************/
/* Closing input and output files */
/**********************************/
// close the input and the output file stream
if(inp) fclose(inp);
if(outp) fclose(outp);
return 0;
}