-
Notifications
You must be signed in to change notification settings - Fork 4
/
parser_common.h
72 lines (54 loc) · 1.12 KB
/
parser_common.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
/*
* File: lexer_common.h
* Author: ideras
*
* Created on August 11, 2016, 3:42 PM
*/
#ifndef PARSER_COMMON_H
#define PARSER_COMMON_H
#include <stdint.h>
#include <string>
#include <list>
#include "mempool.h"
using namespace std;
class MemPool;
extern MemPool *tk_pool;
#define MAX_TOKEN_LENGTH 256
struct TokenInfo {
string tokenLexeme;
uint32_t intValue;
int line;
static void *operator new(std::size_t sz);
static void operator delete(void* ptrb);
TokenInfo() {
tokenLexeme = "";
intValue = 0;
line = 0;
}
void set(string str, int line) {
this->tokenLexeme = str;
this->line = line;
}
};
template <typename T>
struct ParserContext {
ParserContext() {
init();
}
~ParserContext() {
tokenPool.freeAll();
parserPool.freeAll();
instList.clear();
}
void init() {
instList.clear();
tokenPool.freeAll();
parserPool.freeAll();
error = 0;
}
list<T *> instList;
MemPool tokenPool;
MemPool parserPool;
int error;
};
#endif /* PARSER_COMMON_H */