-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
66 lines (57 loc) · 2.07 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Lexico.hpp"
#include "Syntax.hpp"
#include <fstream>
#include <cstdlib>
void lexerTest(std::string ss){
std::fstream* op = new std::fstream(ss);
std::ofstream tab ("lex-"+ss+".txt");
Env* amb = new Env();
Lexico l(op,amb);
Token* t;
do{
t = l.getToken();
if(t->getTag()==Tag::ID) tab<<"\nID: "<<((Word*)t)->lexeme;
else if(t->getTag()==Tag::NUM) tab<<"\nNUM: "<<((Num*)t)->value;
else if(t->getTag()==Tag::EoF) tab<<"\nEOF";
else tab<<"\nTAG: "<<t->getTag()<<"\tLEX: "<<((Word*)t)->lexeme;
}while(t->getTag()!=Tag::EoF);
std::cout<<"\nMap:\n";
auto B = amb->table;
for(auto it=B->begin();it!=B->end();it++) {
if(it->second.getTag()==Tag::ID)
std::cout<<(it->first)<<"\tType: "<<(it->second).type<<std::endl;
else
std::cout<<(it->first)<<"\tTag: "<<it->second.getTag()<<std::endl;
}
}
void syntaxTest(std::string ss, std::string out){
std::fstream* op = new std::fstream(ss);
Env* amb = new Env();
std::ofstream tab ("tabSym-"+ss+".txt");
Lexico l(op,amb);
Syntax s(l, out);
s.startAnalysis();
std::cout<<"\nMap:\n";
auto B = amb->table;
for(auto it=B->begin();it!=B->end();it++) {
if(it->second.getTag()==Tag::ID)
tab<<"ID: "<<(it->first)<<"\tType: "<<(it->second).type<<std::endl;
else
tab<<(it->first)<<"\tTag: "<<it->second.getTag()<<std::endl;
}
}
void compile(std::string ss){
std::string com = "g++ "+ss+".cpp -o "+ss+".exe";
std::system(com.c_str());
}
int main(int argc, char** argv){
if(argc!=3){
std::cout<<"Numero de argumentos errado!!\n O primeiro argumento deve ser o nome do arquivo a ser compilado e o segundo o nome do arquivo a ser gerado";
return 0;
}
std::cout<<"\nCompilando o arquivo: "<<std::string{argv[1]};
lexerTest(std::string{argv[1]});
syntaxTest(std::string{argv[1]}, std::string{argv[2]});
compile(std::string{argv[2]});
return 0;
}