boost::variant(2)、と、なんとかcaperビルド通りました
やった。動いた。
--- variant.000.hpp Sun Sep 19 20:49:50 2004 +++ variant.hpp Thu Oct 19 03:19:36 2006 @@ -633,16 +633,58 @@ private: // helpers, for visitor interfa delete backup_lhs_ptr; // nothrow } +#ifdef __BORLANDC__ + template <typename LhsT> + void backup_assign_impl( + LhsT& lhs_content + ) + { + // Backup lhs content... + LhsT* backup_lhs_ptr = new LhsT(lhs_content); + + // ...destroy lhs content... + lhs_content.~LhsT(); // nothrow + + try + { + // ...and attempt to copy rhs content into lhs storage: + new(lhs_.storage_.address()) RhsT(rhs_content_); + } + catch (...) + { + // In case of failure, copy backup pointer to lhs storage... + new(lhs_.storage_.address()) + backup_holder<LhsT>( backup_lhs_ptr ); // nothrow + + // ...indicate now using backup... + lhs_.indicate_backup_which( lhs_.which() ); // nothrow + + // ...and rethrow: + throw; + } + + // In case of success, indicate new content type... + lhs_.indicate_which(rhs_which_); // nothrow + + // ...and delete backup: + delete backup_lhs_ptr; // nothrow + } +#endif + public: // visitor interface template <typename LhsT> BOOST_VARIANT_AUX_RETURN_VOID_TYPE internal_visit(LhsT& lhs_content, int) { +#ifdef __BORLANDC__ + backup_assign_impl<LhsT>( lhs_content ); +#else typedef typename has_nothrow_move_constructor<LhsT>::type nothrow_move; backup_assign_impl( lhs_content, nothrow_move() ); +#endif BOOST_VARIANT_AUX_RETURN_VOID; }
えーと、そもそもなんでC++Builderでビルドしようと思ったんだったっけ?
ああそうだそうだ、多分VC++2005のランタイムが入って無くて添付のcaper.exeが動かなかったんだ。
ビルドに要したcaper自体への修正は====以下に。template中でenum宣言するとわけわからんエラーを吐くコンパイラが悪い。
私が以前作りかけたずぼら向けパーサジェネレータは、普通に飽きて放置していたのでした。なんか構文木を自動でなど欲しい機能は既にid:jonigataさんの視野に入っているようですので、ビルドも通ったことですし勝手に私の使う言語に対応させたいと思います。
--- lalr.000.hpp Tue Oct 17 20:03:00 2006 +++ lalr.hpp Thu Oct 19 03:41:40 2006 @@ -300,6 +300,13 @@ public: * *==========================================================================*/ +typedef enum { + action_shift, + action_reduce, + action_accept, + action_error, +} type_t; + template < class Token, class Traits > class parsing_table { public: @@ -312,12 +319,7 @@ public: typedef std::vector< rule_type > rules_type; struct action { - enum { - action_shift, - action_reduce, - action_accept, - action_error, - } type; + type_t type; int dest_index; // index to states_ int rule_index; // index to rules_ @@ -1001,7 +1003,7 @@ make_lalr_table( typename parsing_table_type::state::action_table_type::const_iterator k = s->action_table.find( a.token() ); if( k != s->action_table.end() ) { - if( (*k).second.type == parsing_table_type::action::action_reduce ) { + if( (*k).second.type == action_reduce ) { #ifdef ZW_PARSER_LIVECAST std::cerr << "shift/reduce conflict" << std::endl; #endif @@ -1010,7 +1012,7 @@ make_lalr_table( } typename parsing_table_type::action action; - action.type = parsing_table_type::action::action_shift; + action.type = action_shift; action.dest_index = (*next).second; action.rule_index = rule_indices[ x.rule() ]; s->action_table[ a.token() ] = action; @@ -1031,14 +1033,14 @@ make_lalr_table( if( k != s->action_table.end() ) { const rule_type& krule = table.rules()[ (*k).second.rule_index ]; - if( (*k).second.type == parsing_table_type::action::action_shift ) { + if( (*k).second.type == action_shift ) { #ifdef ZW_PARSER_LIVECAST std::cerr << "shift/reduce conflict" << std::endl; #endif srr( krule, x.rule() ); add_action = false; // shiftを優先 } - if( (*k).second.type == parsing_table_type::action::action_reduce && + if( (*k).second.type == action_reduce && !( krule == x.rule() ) ) { #ifdef ZW_PARSER_LIVECAST std::cerr << "reduce/reduce conflict" << std::endl; @@ -1054,13 +1056,13 @@ make_lalr_table( // "reduce A→α"を入れる。 typename parsing_table_type::action a; - a.type = parsing_table_type::action::action_reduce; + a.type = action_reduce; a.rule_index = rule_indices[ x.rule() ]; s->action_table[ x.lookahead().token() ] = a; } else { // c) 項[S'→S・,$]がJiの要素ならば、action[i,$]に"accept"を入れる。 typename parsing_table_type::action a; - a.type = parsing_table_type::action::action_accept; + a.type = action_accept; a.rule_index = rule_indices[ g.root_rule() ]; s->action_table[Traits::eof()] = a; } @@ -1271,14 +1273,14 @@ public: const action_type* a = &((*i).second); switch( a->type ) { - case action_type::action_shift: + case action_shift: #ifdef ZW_PARSER_LIVECAST std::cerr << "shift(" << x << ")\n"; #endif push_stack( a->dest_index, v ); ate = true; break; - case action_type::action_reduce: { + case action_reduce: { const rule_type& rule = rules[ a->rule_index ]; #ifdef ZW_PARSER_LIVECAST std::cerr << "reduce(" << rule << ")\n"; @@ -1295,14 +1297,14 @@ public: } break; } - case action_type::action_accept: { + case action_accept: { #ifdef ZW_PARSER_LIVECAST std::cerr << "accept(" << rules[ a->rule_index ] << ")\n"; #endif run_semantic_action( accept_value_, a->rule_index ); return true; } - case action_type::action_error: + case action_error: default: throw syntax_error(); } @@ -1342,7 +1344,7 @@ private: } private: - table_type table_; + typename Table table_; semantic_actions_type semantic_actions_; value_type accept_value_;
--- grammar.000.hpp Mon Oct 16 12:52:16 2006 +++ grammar.hpp Thu Oct 19 01:59:56 2006 @@ -325,7 +325,7 @@ std::ostream& operator<<( std::ostream& case symbol_type::type_nonterminal: return os << r.name_; default: assert(0); return os; } - return os; + // return os; // 警告を消すためコメントアウト } /*============================================================================
--- caper.000.cpp Tue Oct 17 20:03:00 2006 +++ caper.cpp Thu Oct 19 03:49:44 2006 @@ -17,7 +17,16 @@ #include <algorithm> #include <boost/variant.hpp> #include <boost/scoped_ptr.hpp> + +#ifdef __BORLANDC__ +#include <stdlib> +//#include <locale> +#include <ctype.h> +#undef getc +#undef ungetc +#else #include <boost/algorithm/string/case_conv.hpp> +#endif //////////////////////////////////////////////////////////////// // types @@ -1092,7 +1101,10 @@ void generate_cpp( const tgt::parsing_table& table ) { std::string headername = options.namespace_name; - boost::algorithm::to_upper( headername ); + //boost::algorithm::to_upper( headername ); + for(std::string::iterator i = headername.begin(); i < headername.end(); ++i){ + *i = toupper(*i); + } headername += "_HPP"; // once header @@ -1471,7 +1483,7 @@ void generate_cpp( // action const tgt::parsing_table::action* a = &(*j).second; switch( a->type ) { - case tgt::parsing_table::action::action_shift: + case zw::gr::action_shift: os << " // shift\n" << " push_stack( " << "&Parser::state_" << a->dest_index << ", " @@ -1479,7 +1491,7 @@ void generate_cpp( << "value );\n" << " return false;\n"; break; - case tgt::parsing_table::action::action_reduce: + case zw::gr::action_reduce: os << " // reduce\n"; { size_t base = table.rules()[ a->rule_index ].right().size(); @@ -1528,14 +1540,14 @@ void generate_cpp( } } break; - case tgt::parsing_table::action::action_accept: + case zw::gr::action_accept: os << " // accept\n" << " // run_semantic_action();\n" << " accepted_ = true;\n" << " accepted_value_ = get_arg( 1, 0 );\n" // implicit root << " return false;\n"; break; - case tgt::parsing_table::action::action_error: + case zw::gr::action_error: os << " sa_.syntax_error();\n"; os << " error_ = true;\n"; os << " return false;\n";