Almost done!

functions
Justyna Ilczuk 2012-12-22 19:19:13 +01:00
parent 8ef1eb14c5
commit 10f3eaf214
3 changed files with 18 additions and 4 deletions

View File

@ -38,7 +38,10 @@ void ProgramNode::execute_last()
SenchaObject ProgramNode::evaluate_last() SenchaObject ProgramNode::evaluate_last()
{ {
return static_cast<ASTStatement * >(children[children.size() - 1])->evaluate(); std::cout << "Program evaluates last statement:";
SenchaObject result = (children[children.size() - 1])->evaluate();
std::cout << "It's value is: " << result.repr() << std::endl;
return result;
} }
std::string ProgramNode::debug() std::string ProgramNode::debug()

View File

@ -18,13 +18,17 @@ Parser::~Parser()
void Parser::erase_all() void Parser::erase_all()
{ {
tree.delete_all_children(); /*tree.delete_all_children();
tree.root = new ProgramNode(); tree.root = new ProgramNode();
*/
error_message = "***ERRORS DURING PARSING***\n"; error_message = "***ERRORS DURING PARSING***\n";
position_in_stream = 0; position_in_stream = 0;
in_statement = false; in_statement = false;
program = static_cast<ProgramNode *>(tree.root); this->token_stream = vector<Token>();
delete program;
program = new ProgramNode();
} }

View File

@ -23,14 +23,21 @@ std::string TestParser::test_parsing_and_evaluating_logical_expressions()
Lexer lexer; Lexer lexer;
Context context; Context context;
Parser parser(&context); Parser parser(&context);
ASTInspector inspector;
for(auto logical_case : logical_inputs) for(auto logical_case : logical_inputs)
{ {
auto tokens = lexer.parse_line(logical_case.first); auto tokens = lexer.parse_line(logical_case.first);
parser.add_tokens(tokens); parser.add_tokens(tokens);
auto value = parser.program->evaluate(); cout << parser.show_tokens();
parser.interpret();
inspector.visit(parser.program);
std::cout << inspector.get_report();
inspector.forget_everything();
SenchaObject value = parser.program->evaluate();
parser.erase_all(); parser.erase_all();
muu_assert("Logical value isn't correct", value.truthy == logical_case.second); muu_assert("Logical value isn't correct", value.truthy == logical_case.second);
} }
return test_report; return test_report;
} }