-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpreter.cpp
41 lines (34 loc) · 900 Bytes
/
interpreter.cpp
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
/*
* interpreter.cpp
* Untitled
*
* Created by Ellie on 18/09/10.
* Copyright 2010 Ellie. All rights reserved.
*
*/
#include <cassert>
#include "ast.h"
#include "interpreter.h"
basic::Interpreter::Interpreter(const String &filename) {
m_tokeniser = new Tokeniser(filename);
assert(m_tokeniser != NULL);
m_parser = new Parser(m_tokeniser);
assert(m_parser != NULL);
}
basic::Interpreter::Interpreter(FILE *file) {
m_tokeniser = new Tokeniser(file);
assert(m_tokeniser != NULL);
m_parser = new Parser(m_tokeniser);
assert(m_parser != NULL);
}
basic::Interpreter::~Interpreter() {
delete m_parser;
delete m_tokeniser;
}
void basic::Interpreter::interpret() const {
Unit *parse_tree = NULL;
while ((parse_tree = m_parser->parse())) {
parse_tree->execute();
if (not parse_tree->installed()) delete parse_tree;
}
}