-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableparser.h
48 lines (34 loc) · 878 Bytes
/
tableparser.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
#pragma once
#include <map>
#include <stack>
#include <vector>
#define YYLOG stdout
#define YYBUFSIZE 2048
class TableParser
{
protected:
using Symbols = int;
using Rule = int;
using LexicalAnalyzer = int(*)();
LexicalAnalyzer yylex;
// parsing table
std::map< Symbols, std::map<Symbols, Rule> > table;
std::map<Symbols, Rule> actions;
// symbol stack
std::stack<Symbols> ss;
bool yydebug = false;
public:
TableParser(LexicalAnalyzer lexer) { yylex = lexer; };
~TableParser() = default;
void setDebug(bool onoff) {
yydebug = onoff;
}
virtual int yyparse();
virtual void yyerror(const std::string &str);
virtual void yywarning(const std::string &str);
virtual void yylog(const char *fmt, ...);
virtual void initTable() = 0;
virtual int yyrule(int rule) = 0;
virtual int yyaction(int action) = 0;
virtual void tokenMatch(int token) = 0;
};