-
Notifications
You must be signed in to change notification settings - Fork 0
/
lua_driver.hh
99 lines (74 loc) · 1.86 KB
/
lua_driver.hh
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "parser.hpp"
#include "nodes.hh"
#include <map>
#include <string>
#include <vector>
#include <memory>
class lua_driver
{
public:
lua_driver() {};
virtual ~lua_driver();
std::map<std::string, int> variables;
int result;
// Handling the scanner.
void scan_begin ();
void scan_end ();
bool trace_scanning;
// Run the parser. Return 0 on success.
int parse (const std::string& f);
// Error handling.
void error (const yy::location& l, const std::string& m);
void error (const std::string& m);
const std::vector<Node *> getNodes() const;
const std::vector<Node *> getExpressionNodes() const {
return expressionNodes;
}
template<class T, typename... Args>
Node *createNode(Args... args) {
Node *n = new T(args...);
addNode(n);
return n;
}
void addNode(Node *);
void setRootNode(Node *rootNode);
Node *getRootNode();
private:
std::string file;
bool trace_parsing;
std::shared_ptr<yy::parser> parser;
std::shared_ptr<Scanner> scanner;
std::vector<Node *> expressionNodes;
Node *rootNode = nullptr;
};
#if ! defined(yyFlexLexerOnce)
#include <FlexLexer.h>
#endif
#undef YY_DECL
#define YY_DECL int Scanner::yylex()
class Scanner : public yyFlexLexer{
public:
Scanner(std::istream *in) : yyFlexLexer(in),
yylval( nullptr ){};
virtual ~Scanner();
int yylex(yy::parser::semantic_type *lval)
{
yylval = lval;
return( yylex() );
}
template<class T, typename... Args>
Node *createNode(Args... args) {
Node *n = new T(args...);
addAndAssinNode(n);
return n;
}
const std::vector<Node *> getNodes() const;
void addAndAssinNode(Node *n);
private:
/* hide this one from public view */
int yylex();
/* yyval ptr */
yy::parser::semantic_type *yylval;
std::vector<Node *> nodes;
};