forked from eliasdiegoperez/Compiler323
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (42 loc) · 1.3 KB
/
main.cpp
File metadata and controls
62 lines (42 loc) · 1.3 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
#include "Syntax.h"
int main()
{
Lexer lex;
Syntax syn;
vector<TokenType> tokens; //vector to hold tokens as they are being inputted
string current = "";
string infilepath = "fin.txt";
string outfilepath = "fout.txt";
int lineNumber = 0;
//Input file to read from
//cout << "Enter the source code file name: ";
//cin >> infilepath;
//Output file to write to
//cout << "Enter the output file: ";
//cin >> outfilepath;
fin.open(infilepath);
fout.open(outfilepath);
//Catch issue with opening file
if (!fin)
{
cout << "Error. Unable to read file." << endl;
return -1;
}
//While not end of file, read every line.
while (getline(fin, current))
{
lineNumber++;
tokens = lex.lexical(current, lineNumber);
for (int i = 0; i < tokens.size(); i++) {
tokens[i].linenum = lineNumber;
//fout << tokens[i].lexeme << " - " << tokens[i].token << endl;
}
tokenList.insert(tokenList.end(), tokens.begin(), tokens.end());
tokens.clear();
}
fin.close();
syn.Rat18S();
fout.close();
cout << "Results printed in output file.\n";
return 0;
}