-
Notifications
You must be signed in to change notification settings - Fork 1
/
LexicalAnalyzer.cpp
101 lines (86 loc) · 1.73 KB
/
LexicalAnalyzer.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include<string>
#include<fstream>
#include<deque>
#include"LexicalAnalyzer.class.h"
bool LexicalAnalyzer::open(const std::string &path)
{
int type;
std::string word;
if(path.size()>0)//文件操作
{
this->inputreader=&this->filereader;
if(!this->filereader.open(path)) return false;
}
else//控制台输入操作
{
this->inputreader=&this->consoleinputreader;
}
if(!this->getsym(word,type)) return false;
this->cursymtype=type;
this->cursymword=word;
return true;
}
void LexicalAnalyzer::next()
{
int type;
std::string word;
this->prevsymtype=this->cursymtype;
this->prevsymword=this->cursymword;
this->getsym(word,type);
this->cursymtype=type;
this->cursymword=word;
}
int LexicalAnalyzer::peeksymtype() const
{
return this->cursymtype;
}
int LexicalAnalyzer::getsymtype()
{
if(!this->eof())
{
this->next();
return this->getprevsymtype();
}
else return this->peeksymtype();
}
std::string LexicalAnalyzer::peeksymword() const
{
return this->cursymword;
}
std::string LexicalAnalyzer::getsymword()
{
if(!this->eof())
{
this->next();
return this->getprevsymword();
}
else return this->peeksymword();
}
int LexicalAnalyzer::getprevsymtype() const
{
return this->prevsymtype;
}
std::string LexicalAnalyzer::getprevsymword() const
{
return this->prevsymword;
}
bool LexicalAnalyzer::eof() const
{
return this->inputreader->eof();
}
int LexicalAnalyzer::get_curline() const
{
return this->cursymline;
}
int LexicalAnalyzer::get_curchar() const
{
return this->cursymchar;
}
int LexicalAnalyzer::get_prevline() const
{
return this->prevsymline;
}
int LexicalAnalyzer::get_prevchar() const
{
return this->prevsymchar;
}