-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·75 lines (59 loc) · 2.23 KB
/
main.cpp
File metadata and controls
executable file
·75 lines (59 loc) · 2.23 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
65
66
67
68
69
70
71
72
73
74
#include <iostream>
using namespace std;
#include "LexiconAnalyzer.h"
int main() {
string filename;
LexiconAnalyzer lex;
cout << "Informe o nome do arquivo: " << endl;
cin >> filename;
ifstream file(filename);
DFA identifierDFA("identifiers.txt");
DFA integerDFA("whoneNumbers.txt");
DFA floatDFA("realNumbers.txt");
DFA stringDFA("strings.txt");
if (file.is_open()) {
string line;
string token;
char nextChar;
while (getline(file, line)) {
for (int i = 0; i < line.length(); i++) {
nextChar = line[i];
if (lex.isWhitespace(nextChar)) {
lex.analyze(token, &identifierDFA, &integerDFA, &floatDFA, &stringDFA);
token.clear();
}
else if (lex.isSymbol(nextChar)) {
lex.analyze(token, &identifierDFA, &integerDFA, &floatDFA, &stringDFA);
token.clear();
cout << setw(24) << left << nextChar << right << "Symbol" << endl;
lex.writeCharInFile("lexLog.txt",nextChar,"Symbol");
}
else if (lex.isOperator(nextChar)) {
lex.analyze(token, &identifierDFA, &integerDFA, &floatDFA, &stringDFA);
token.clear();
cout << setw(24) << left << nextChar << right << "Operator" << endl;
lex.writeCharInFile("lexLog.txt",nextChar,"Operator");
}
else if (nextChar == '"'){
lex.analyze(token, &identifierDFA, &integerDFA, &floatDFA, &stringDFA);
token.clear();
token.push_back(nextChar);
i++;
nextChar = line[i];
while(nextChar != '"') {
token.push_back(nextChar);
i++;
nextChar = line[i];
}
token.push_back(nextChar);
}
else {
token.push_back(nextChar);
}
}
}
} else {
cout << "Erro ao abrir arquivo " << filename << endl;
}
return 0;
}