-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToken.cpp
More file actions
34 lines (26 loc) · 677 Bytes
/
Copy pathToken.cpp
File metadata and controls
34 lines (26 loc) · 677 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
27
28
29
30
31
32
33
34
#include "Token.h"
#include <iostream>
using namespace std;
TokenClass::TokenClass(){
}
TokenClass::TokenClass(TokenType type, const string & lexeme){
mType = type;
mLexeme = lexeme;
}
void TokenClass::CheckReserved(){
if (mType == IDENTIFIER_TOKEN){
if (mLexeme == "void"){
mType = VOID_TOKEN;
}else if(mLexeme == "main"){
mType = MAIN_TOKEN;
}else if(mLexeme == "int"){
mType = INT_TOKEN;
}else if(mLexeme == "cout"){
mType = COUT_TOKEN;
}
}
}
std::ostream & operator<<(std::ostream & out, const TokenClass & tc){
out << tc.GetTokenType() << " " << tc.GetTokenTypeName() << " " << tc.GetLexeme();
return out;
}