-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenParser.h
61 lines (56 loc) · 1.39 KB
/
tokenParser.h
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
#include "Buffer.h"
#include <vector>
//Declears
struct TokenPair {
std::string token;
std::string ID;
};
class TokenParser {
public :
//Constructor
explicit TokenParser(std::string filePath);
private :
//Private Vars
Buffer charBuffer;
std::string KEYS[50] = {
"int", "if", "while", "do", "float",
"double", "short", "long", "unsigned",
"char", "return", "class", "struct",
"enum", "static", "const", "signed",
"sizeof", "else", "switch", "case",
"default", "for", "break", "goto",
"continue", "auto", "void", "null",
"nullptr", "typedef"
};
std::string OP[50] = {
"+", "-", "*", "/", "++", "--", "=",
"+=", "-=", "*=", "/=", "%", "%=",
"<<", ">>", "<<=", ">>=", "||", "&&",
"!", "|", "&", "==", "!=", "~", "^",
"^=", "<", ">", "<=", ">=", "\?",
":", ".", "->", "::", "|=", "&="
};
std::string DELIMITER[50] = {
";", "(", ")", "{", "}", "[", "]", ","
};
int whichLine;
int whichChar;
int curState;
char nowCh;
std::string curLexeme;
std::vector<TokenPair> tokenSaver;
//Private methods
void throwErr();
bool isDigit(char tmp);
bool isAlpha(char tmp);
bool isUnderLine(char tmp);
void getNextChar();
bool isKeys(std::string token);
bool isOps(std::string token);
bool isDelimiters(char token);
bool isOpsForChar(char tmp);
public :
//Public methods
void LexemeAnalyze();
void outputResult();
};