-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lexer.h
68 lines (57 loc) · 959 Bytes
/
Lexer.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
#ifndef LEXER_H
#define LEXER_H
#include <QtCore/QString>
#include <QtCore/QVariant>
class Lexer
{
public:
enum Token
{
Invalid = 0,
EndOfFile,
Identifier,
StringLiteral,
IntegerLiteral,
FloatLiteral,
BoolLiteral,
LeftParenthesis,
RightParenthesis,
Comma,
EqualSign,
PlusSign,
MinusSign,
MulSign,
DivSign,
ModuloSign,
ScopeOperator,
// Keywords
Keyword_var,
Keyword_true,
Keyword_false
};
public:
Lexer(const QString &sourceText);
Token getNextToken();
QVariant lastReadValue() const { return m_lastValue; }
Token lookAhead();
int currentLine() const
{
return m_currentLine;
}
int currentColumn() const
{
return m_currentColumn;
}
private:
Lexer::Token isKeyword(const QString& value) const;
void consumeChar();
void consumeWhitespace();
private:
QString m_sourceText;
QVariant m_lastValue;
quint32 m_charIndex;
QChar m_lastChar;
int m_currentLine;
int m_currentColumn;
};
#endif