-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart_a.cpp
53 lines (46 loc) · 1.39 KB
/
part_a.cpp
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
/*
* SET07109 Coursework 2: Implementing a compiler symbol table (Part A)
* --------------------------------------------------------------------
* a program that reads a .c file and creates a symbol table which is,
* - printed to console,
* - and to a .txt file
* author: Vinh Phat Tu (40507973)
* last date of modification: April 2021
*/
#include "symbol_table.hpp"
#include <iostream>
#include <fstream>
using namespace std;
#define TEXT_FILE_NAME "identifiers.txt"
/*
* Main function: main
* -------------------
* collects the first command line argument,
* creates symbol table,
* prints to console,
* and writes to a .txt file
*
* parameters:
* - argc: number of command line arguments
* - argv: command line arguments
*
* returns: int
* - 0 = error-free execution
*/
int main(int argc, char **argv)
{
//Read in .c file and create struct
string CFile_name = argv[1];
unique_ptr<CFile> file_struct_ptr = read_CFile(CFile_name);
//Prints symbol table to console
cout << endl;
cout << "Symbol table of: " << CFile_name << endl;
cout << "------------------------" << endl;
print_output(file_struct_ptr);
cout << "------------------------" << endl;
//Write table to .txt file
ofstream file(TEXT_FILE_NAME);
write_symbol_table(file_struct_ptr, file);
file.close();
return 0;
}