-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
64 lines (57 loc) · 1.55 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
#include "header.h"
#include "parameter.h"
#include "symbol.h"
#include "error.h"
#include "grammer.h"
using namespace std;
Symbol sym;
Grammer grammer;
void scan_and_print_token(){
int count = 0;
while(sym.getNextSymbol()){
//while(true){
int s = sym.symbol;
if (s == 0){ // error
cout << count << "\t:\t" << Type::type_message[0] << endl;
} else
if (s <= 2){ // number
cout << count << "\t:\t" << Type::type_message[s] << "\t" << sym.num << endl;
} else
if (s == 3){ // char
cout << count << "\t:\t" << Type::type_message[s] << "\t\t\'" <<
sym.chr << "\'" << endl;
} else
if (s == 4){ // string
cout << count << "\t:\t" << Type::type_message[s] << "\t\t\"" <<
sym.name << "\"" << endl;
} else
if (s <=24){ // operator
cout << count << "\t:\t" << Type::type_message[s] << endl;
}else{ //reserved_word / identifier
cout << count << "\t:\t" << Type::type_message[s] << "\t" << sym.name << endl;
}
count ++;
}
}
char *file;
void init(){
//freopen("out.txt","w",stdout);
//sym.setUp("source.txt");
sym.setUp(file);
//freopen("out.txt","w",stdout);
Type::init();
grammer.set_sym(&sym);
}
int main(int argc, char **argv)
{
freopen("out.txt","w", stdout);
if (argc==2){
file = argv[1];
}else{
file = "14061187_test.txt";
}
init();
grammer.start();
//scan_and_print_token();
return 0;
}