-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.h
69 lines (62 loc) · 1008 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
69
#ifndef lexer
#define lexer
#include <vector>
#include <string>
// Token types enum
enum TokenType {
NUM,
VAR,
PLUS,
MINUS,
TIMES,
SLASH,
LPAREN,
RPAREN,
WS,
NL,
TAB,
EQUAL,
KEYWORD,
COMMA,
COLON,
LESS,
GREATER,
SEMICOLON,
STRING,
DOT,
END
};
// Classes
class Token{
public:
TokenType type;
std::string value;
Token(TokenType type, std::string value);
Token();
TokenType get_type();
std::string get_value();
// Overwriting stream operator << to print the Token
friend std::ostream& operator<<(std::ostream& os, const Token& t);
};
class Tokens {
public:
std::vector<Token> tokens;
Tokens(std::vector<Token>, std::string);
Token current();
Token next();
Token next(int index);
void eat();
std::string getCodeContext();
int getLineNumber();
void print();
private:
int lineNumber;
std::string source_code;
};
class Lexer {
public:
Tokens lex(std::string programm);
void print(Tokens);
};
std::string lexEscapeSequence(char, int);
#endif