-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (47 loc) · 1.35 KB
/
Copy pathmain.cpp
File metadata and controls
49 lines (47 loc) · 1.35 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
// main.cpp
#include <iostream>
#include "analiseLexica.h" // Cabeçalho da análise léxica
#include "analiseSintatica.h" // Cabeçalho da análise sintática
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <unordered_map>
#include <cctype>
using namespace std;
int main()
{
string nome_arquivo;
cout << "Informe o nome do arquivo a ser analisado: ";
cin >> nome_arquivo;
// Lê o código do arquivo
string codigo = lerArquivo(nome_arquivo);
if (codigo.empty())
{
cerr << "Erro ao ler o arquivo." << endl;
return 1;
}
unordered_map<string, int> tabelaDeTokens = criarTabelaDeTokens();
try
{
// Realiza a análise léxica (tokenização)
vector<Token> tokens = analiseLexica(codigo, tabelaDeTokens);
int tokenIndex = 0;
cout << "Tokens gerados:" << endl;
for (const auto &token : tokens)
{
cout << "Token tipo: " << token.tipo
<< ", lexema: '" << token.lexema
<< "', linha: " << token.linha
<< ", coluna: " << token.coluna << endl;
}
program(tokens, tokenIndex); // Chama a função principal da análise sintática
cout << "Analise sintatica concluida com sucesso!" << endl;
}
catch (const exception &e)
{
cerr << "Erro: " << e.what() << endl;
return 1;
}
return 0;
}