/
Main.cpp
53 lines (45 loc) · 973 Bytes
/
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
/**
*
* @authors zh.wen (zh.wen@hotmail.com)
* @date 2016-01-04 00:29:55
*
**/
#include"Parser.h"
int main()
{
ifstream input;
ofstream tokenList , sTree, cFile ;
string filename = "file";
cout << "input the filename" << endl;
//cin >> filename;
input.open(filename, ios::in);
if (!input)
{
cout << "can't read the file '" << filename << "'" << endl;
exit(1);
}
tokenList.open("tokenList.dat", ios::out);
if (!tokenList)
{
cout << "can't write the file 'tokenList.dat'" << endl;
exit(2);
}
sTree.open("sTree.dat", ios::out);
if(!sTree)
{
cout << "can't write the file 'sTree.dat'" << endl;
exit(2);
}
cFile.open("cFile.c", ios::out);
if (!cFile)
{
cout << "can't write the file 'tokenList.dat'" << endl;
exit(2);
}
Lexer *lexer = new Lexer(&input);
Parser *parser = new Parser(lexer);
lexer->setGramTreeFile(&tokenList);
Program *program = parser->parse();
program->createSTree(0, &sTree);
program->genC(&cFile);
}