-
Notifications
You must be signed in to change notification settings - Fork 0
/
lua_driver.cc
76 lines (60 loc) · 1.45 KB
/
lua_driver.cc
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
#include <iostream>
#include <fstream>
#include <string>
#include <assert.h>
#include "parser.hpp"
#include "lua_driver.hh"
lua_driver::~lua_driver () {
for(auto p : expressionNodes) {
delete p;
}
expressionNodes.clear();
}
void lua_driver::error (const yy::location& l, const std::string& m) {
std::cout << "error: " << l << ": " << m << std::endl;
}
void lua_driver::error (const std::string& m) {
std::cout << "error: " << m << std::endl;
}
int lua_driver::parse (const std::string& f) {
std::ifstream in_file( f.c_str() );
if( ! in_file.good() ) exit( EXIT_FAILURE );
scanner.reset( new Scanner( &in_file ) );
/* check to see if its initialized */
assert( scanner != nullptr );
parser.reset(new yy::parser( *scanner, *this ) );
// parser->set_debug_level(7);
assert( parser != nullptr );
if( parser->parse() )
{
std::cerr << "Parse failed!!\n";
}
return 0;
}
void lua_driver::addNode(Node *n) {
n->setLocation(scanner->lineno());
expressionNodes.push_back(n);
}
const std::vector<Node *> lua_driver::getNodes() const {
return scanner->getNodes();
}
void lua_driver::setRootNode(Node *rootNode) {
this->rootNode = rootNode;
}
Node *lua_driver::getRootNode() {
return rootNode;
}
const std::vector<Node *> Scanner::getNodes() const {
return nodes;
}
void Scanner::addAndAssinNode(Node *n) {
yylval->node = n;
n->setLocation(lineno());
nodes.push_back(n);
}
Scanner::~Scanner() {
for(auto p : nodes) {
delete p;
}
nodes.clear();
}