-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileLexer.h
97 lines (77 loc) · 1.56 KB
/
FileLexer.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
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
#ifndef FILE_LEXER_H_
#define FILE_LEXER_H_
#include <fstream>
#include <string>
#include <vector>
class LexerReader
{
public:
LexerReader( const std::string &filename );
char operator[]( int i );
char popChar();
void popChar( int count );
char peekChar();
bool isEOF();
private:
std::ifstream mFile;
};
class Lexer
{
public:
Lexer( LexerReader *reader );
int peekSymbol();
int getSymbol();
const std::string &getSymbolText();
int getCurrentPos();
void setCurrentPos( int pos );
enum LexerSymbols {
BUILTIN_TYPE,
TYPE_MODIFIER,
KEYWORD_ELSE,
KEYWORD_FOR,
KEYWORD_IF,
KEYWORD_WHILE,
KEYWORD_RETURN,
VOID,
SYMBOL,
CONSTANT_STRING,
CONSTANT_CHAR,
CONSTANT_NUMBER,
LOR,
LAND,
EQ,
ASSIGN,
SHIFT,
NUM_SYMBOLS
};
bool isEOF() { return mReader->isEOF(); }
uint32_t getLineNumber() { return lineno; }
uint32_t getLinePosition() { return charPos; }
protected:
bool match( const char *match_str );
bool matchKeyword( const char *match_str );
void readSymbol();
void readStringConst();
void readCharacterConst();
void readConst();
void handleComment( bool singleLine );
bool isAlpha( char c );
bool isAlphaNum( char c );
int getSymbolInternal();
int getSymbolFromFile();
private:
LexerReader *mReader;
std::string mMatchString;
int mLastSym;
uint32_t lineno;
uint32_t charPos;
struct SymbolInfo
{
SymbolInfo( int s, std::string &str ) : symbol( s ), symbolText( str ) {}
int symbol;
std::string symbolText;
};
std::vector<SymbolInfo> mSymbolList;
int mCurrentPos;
};
#endif // FILE_LEXER_H_