-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken.cpp
More file actions
26 lines (21 loc) · 749 Bytes
/
Copy pathtoken.cpp
File metadata and controls
26 lines (21 loc) · 749 Bytes
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
#include "token.h"
TokenClass::TokenClass()
: mType(BAD_TOKEN), mLexeme("")
{
}
TokenClass::TokenClass(TokenType type, const string & lexeme)
: mType(type), mLexeme(lexeme)
{
}
void TokenClass::CheckReserved() {
if(mLexeme.compare("void") == 0) { mType = VOID_TOKEN; }
else if(mLexeme.compare("main") == 0) { mType = MAIN_TOKEN; }
else if(mLexeme.compare("int") == 0) { mType = INT_TOKEN; }
else if(mLexeme.compare("cout") == 0) { mType = COUT_TOKEN; }
else if(mLexeme.compare("if") == 0) { mType = IF_TOKEN; }
else if(mLexeme.compare("while") == 0) { mType = WHILE_TOKEN; }
}
ostream & operator<<(ostream & out, const TokenClass & tc) {
out << tc.GetTokenTypeName() << " " << tc.GetLexeme();
return out;
}