diff --git a/src/cpp.cc b/src/cpp.cc index 58cf819af..88d887f95 100644 --- a/src/cpp.cc +++ b/src/cpp.cc @@ -1033,7 +1033,7 @@ void Printer::Cpp::print_eqs(const std::list &l, char c) { } -void Printer::Cpp::print_most_decl(const Symbol::NT &nt) { +void Printer::Cpp::print_most_decl(const Symbol::NT &nt) { // header instance variables in class out for resulting out.hh ::Type::Base *type = new Type::Size(); for (size_t t = nt.track_pos(); t < nt.track_pos() + nt.tracks(); ++t) { stream << indent() << *type << " t_" << t << "_left_most;" << endl; @@ -1075,7 +1075,7 @@ void Printer::Cpp::print_window_inc(const Symbol::NT &nt) { } -void Printer::Cpp::print(const Statement::Table_Decl &t) { +void Printer::Cpp::print(const Statement::Table_Decl &t) { // Should print statements in Header of out.hh in_class = true; bool wmode = ast && ast->window_mode; bool checkpoint = ast && ast->checkpoint && !ast->checkpoint->is_buddy; @@ -1928,8 +1928,11 @@ void Printer::Cpp::print_subseq_typedef(const AST &ast) { << ", unsigned> TUSubsequence;\n\n"; } +void Printer::Cpp::enum_graph_print(){ + stream << indent() << "unsigned int parentID" << endl; +} -void Printer::Cpp::header(const AST &ast) { +void Printer::Cpp::header(const AST &ast) { //generates out.hh prints if (!ast.code_mode().subopt_buddy()) { stream << endl << make_comments(id_string, "//") << endl << endl; stream << "#ifndef " << class_name << "_hh" << endl @@ -2482,8 +2485,15 @@ void Printer::Cpp::backtrack_footer(const AST &ast) { print_subopt_fn(ast); } +void Printer::Cpp::backtrack_tree_footer(const AST &ast) { + print_value_pp_tree(ast); + print_backtrack_fn(ast); + print_backtrack_pp(ast); + print_subopt_fn(ast); +} -void Printer::Cpp::print_value_pp(const AST &ast) { +//------------------------------------------------------------------------------------------------------------ +void Printer::Cpp::print_value_pp_tree(const AST &ast) { stream << indent() << "template "; stream << " void print_result(std::ostream &out, " << "Value&" << " res) {" << endl; @@ -2499,6 +2509,8 @@ void Printer::Cpp::print_value_pp(const AST &ast) { stream << indent() << "std::lock_guard lock(print_mutex);" << endl; } + stream << indent() << "std::ofstream file_stream(\"trees.tex\");" << endl; + stream << indent() << "if (isEmpty(res)) {" << endl; inc_indent(); stream << indent() << "out << \"[]\\n\";" << endl; @@ -2506,9 +2518,39 @@ void Printer::Cpp::print_value_pp(const AST &ast) { stream << indent() << "} else {" << endl; inc_indent(); stream << indent() << "out << res << '\\n';" << endl; - dec_indent(); + stream << indent() << "file_stream << res << '\\n' << std::endl;" << endl; + indent(); stream << indent() << '}' << endl; + dec_indent(); + stream << indent() << '}' << endl << endl; + } +//------------------------------------------------------------------------------------------------------------ +void Printer::Cpp::print_value_pp(const AST &ast) { + stream << indent() << "template "; + stream << " void print_result(std::ostream &out, " + << "Value&" << " res) {" << endl; + inc_indent(); + if (ast.code_mode() == Code::Mode::BACKTRACK || + ast.code_mode() == Code::Mode::SUBOPT) { + dec_indent(); + stream << indent() << '}' << endl; + return; + } + if (ast.checkpoint && !ast.checkpoint->is_buddy && + !ast.outside_generation()) { + stream << indent() + << "std::lock_guard lock(print_mutex);" << endl; + } + stream << indent() << "if (isEmpty(res)) {" << endl; + inc_indent(); + stream << indent() << "out << \"[]\\n\";" << endl; + dec_indent(); + stream << indent() << "} else {" << endl; + inc_indent(); + stream << indent() << "out << res << '\\n';" << endl; + indent(); + stream << indent() << '}' << endl; dec_indent(); stream << indent() << '}' << endl << endl; } diff --git a/src/cpp.hh b/src/cpp.hh index c93963bd7..de87ed95c 100644 --- a/src/cpp.hh +++ b/src/cpp.hh @@ -81,6 +81,7 @@ class Cpp : public Base { void print_stats_fn(const AST &ast); void print_value_pp(const AST &ast); + void print_value_pp_tree(const AST &ast); void print(const std::list &types, const std::list &names); @@ -177,6 +178,7 @@ class Cpp : public Base { void print(const Type::Multi &expr); + void enum_graph_print(); void header(const AST &ast); void header_footer(const AST &ast); void footer(const AST &ast); @@ -199,6 +201,7 @@ class Cpp : public Base { public: void backtrack_footer(const AST &ast); + void backtrack_tree_footer(const AST &ast); private: void print(const std::list &l); diff --git a/src/gapc.cc b/src/gapc.cc index 71e6b0c5c..1a3e56976 100644 --- a/src/gapc.cc +++ b/src/gapc.cc @@ -368,6 +368,9 @@ class Main { driver.ast.set_outside_nt_list(&opts.outside_nt_list); driver.parse_product(opts.product); + + + if (driver.is_failing()) { throw LogError("Seen parse errors."); } @@ -450,6 +453,7 @@ class Main { */ void back(Instance *i = 0, Instance *instance_buddy = 0) { Instance *instance = i; + if (!i || instance_buddy) { if (opts.backtrack || opts.subopt || opts.kbacktrack) { instance = driver.ast.split_instance_for_backtrack(opts.instance); @@ -679,6 +683,8 @@ class Main { + opts.plot_grammar_file + " > foo.pdf' to generate a PDF."); } + + driver.ast.set_class_name(opts.class_name); @@ -739,9 +745,14 @@ class Main { bt->print_header(hh, driver.ast); bt->print_body(cc, driver.ast); } + // Hier nach Trees checken. Dann müsste man die print funktion in backtrack_footer dynamisch wechseln können + // Dann müsste ich schonmal eine Datei aus dem Output generieren können - hh.backtrack_footer(driver.ast); - + if (opts.product == "trees") { + hh.backtrack_tree_footer(driver.ast); + } else { + hh.backtrack_footer(driver.ast); + } hh.close_class(); }