-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.h
56 lines (48 loc) · 859 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
#include <string>
#include <unordered_map>
#pragma once
using namespace std;
enum TokenType {
NUM, //0
ADD, //1
SUB, //2
MULT, //3
DIV, //4
SEMI, //5
OPAREN, //6
CPAREN, //7
END, //8
ID, //9
EQUAL, //10
LESSTHAN, //11
GREATERTHAN, //12
IF, //13
ELSE, //14
OBRACE, //15
CBRACE, //16
WHILE, //17
PRINT, //18
EMPTY //19
};
struct Token {
Token();
Token(TokenType tt, string t);
TokenType tokenType;
string value;
};
bool operator==(const Token& lhs, const Token& rhs);
class Lexer {
private:
string program;
int nextTokenStart;
bool isTerminal(char c);
Token prevToken;
Token getMultiCharToken(string currTokenValue);
public:
static const int INVALID_TOKEN = 15;
static const int INVALID_NUMBER = 16;
Lexer(string program);
bool hasNextToken();
Token getNextToken();
Token peek();
};