-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtokenizer.h
77 lines (64 loc) · 1.59 KB
/
tokenizer.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
/*
* File: Tokenizer.h
* --------------
* This file provides support to scan codes and divide it into tokens.
*/
#ifndef Tokenizer_H
#define Tokenizer_H
#include <QList>
#include <QMap>
#include <QString>
#include <QStringList>
#include <QTextStream>
#include <QSet>
/* enum : Token Type */
enum TokenType {WORD, RESERVEREDWORD, NUMBER, OPERATOR, STRING, EMPTY};
class Tokenizer
{
private:
QStringList TokenList;
QSet<QString> validOp { "+", "-" , "*" , "/", "(" , ")" , "=", ">", "<" };
QSet<QString> reservedWord { "THEN", "GOTO" , "LET" , "RUN" };
int scanLocation;
public slots:
Tokenizer();
/*
* Method: scanLine
* --------------
* Scan a line, split the line into tokens by blankspace
* and stores the tokens in the TokenList.
*/
void scanLine(QString line);
/*
* Method: trackback
* --------------
* Go back to scan the previous token.
*/
void trackback();
/*
* Method: getLineNum
* --------------
* Get the line nummber of the code this Tokenizer is scanning.
* If the code does not begin with a line number, return -1.
*/
int getLineNum();
/*
* Method: hasMoreTokens
* --------------
* Check whelter there are more tokens.
*/
bool hasMoreTokens();
/*
* Method: getNextToken
* --------------
* Return next token in the form of QString.
*/
QString getNextToken();
/*
* Method: getTokenType
* --------------
* Return the type of the token.
*/
TokenType getTokenType(QString token);
};
#endif // Tokenizer_H