xiiregexbuilder
FPGA-Accelerated Regular Expression Matching Enginesrc/lexer.h (921B)
1#ifndef LEXER_H
2#define LEXER_H
3
4#include <string>
5#include <vector>
6#include <ostream>
7
8enum class TokenType {
9 LITERAL,
10 DOT,
11 STAR,
12 PLUS,
13 QUESTION,
14 PIPE,
15 LPAREN,
16 RPAREN,
17 LBRACKET,
18 RBRACKET,
19 END_OF_INPUT
20};
21
22struct Token {
23 TokenType type;
24 char value; // Meaningful for LITERAL, otherwise ignored or holds the char representation
25 int line; // Useful for error reporting
26 int column; // Useful for error reporting
27
28 Token(TokenType t, char v = 0, int l = 0, int c = 0)
29 : type(t), value(v), line(l), column(c) {}
30};
31
32std::string tokenTypeToString(TokenType type);
33
34class Lexer {
35public:
36 explicit Lexer(const std::string& input, int lineNum = 0);
37 std::vector<Token> tokenize();
38
39private:
40 std::string input;
41 size_t pos;
42 int line;
43 int col;
44
45 char peek() const;
46 char advance();
47 bool isAtEnd() const;
48};
49
50#endif // LEXER_H