1

おもちゃの言語の構文ツリーを構築するために属性伝播を使用しています。if ステートメントの定義で問題が発生しました。エラー メッセージからはわかりにくいのですが、rhs 属性が期待される属性に崩壊していないと思います。tuple <double,Statement,optional<Statement>>それは私が思うに崩壊するはずです。

エラー:C:\Program Files (x86)\CodeBlocks\MinGW\boost_1_43_0\boost\variant\variant.hpp|1293|error: no matching function for call to 'boost::detail::variant::make_initializer_node::apply<boost::mpl::pair<boost::detail::variant::make_initializer_node::apply<boost::mpl::pair<boost::detail::variant::initializer_root, mpl_::int_<0> >, boost::mpl::l_iter<boost::mpl::list3<boost::recursive_wrapper<Lang::CompoundStatement>, boost::recursive_wrapper<Lang::IfStatement>, Lang::VarStatement> > >::initializer_node, mpl_::int_<1> >, boost::mpl::l_iter<boost::mpl::list2<boost::recursive_wrapper<Lang::IfStatemen [error cuts out here]

ありがとう。

PS コードを正しく表示できませんでした。ここにプレーンテキスト バージョンがあります: http://freetexthost.com/a3smzx0zk5

PPS 言及するのを忘れたいくつかの情報。削除"else" >>してに変更> statementすると機能しますが>> statement"else" >> statementステートメントだけに折りたたむ必要があります。「else」を qi::lit として明示的に作成しても役に立ちません。

4

2 に答える 2

3

シーケンスoperator>>()と期待operator>()は、属性の処理に関してうまく混ざりません。同じ式で両方の演算子を使用すると、属性全体がフラット化されません。どちらか一方のみを使用している場合に発生します。

このため、式によって公開される属性:

if_statement %= "if" > qi::double_ > statement >> -("else" > statement) ;

は:

tuple <tuple <double, Statement>, optional<Statement> >

コンパイルの問題を説明しています。式を次のように書き換えます。

if_statement %= "if" > qi::double_ > statement > -("else" > statement) ;

ただし、(セマンティクスを変更せずに) 問題を解決する必要があります。

于 2010-08-23T12:14:43.003 に答える
0

ええと、編集もコメントもできないようですので、これを回答として投稿する必要があります。

ルールを if ステートメント ルールと if-else ステートメント ルールに分割することで、この問題を回避しました。しかし、init 宣言の私の定義では、問題が再発します。
init_decl %= identifier >> -('=' >> expression) ;

identifier %= lexeme[(alpha | char_('')) >> *(alnum | char('_'))] ;

expression %= literal ;

literal %= real_literal | string_literal ;

real_literal %= double_ ;

string_literal %= lexeme['"' >> *(char_ - '"') >> '"'] ;

前と同じ問題。しかし、最初は問題の調査がうまくいきませんでした。

In member function 'void boost::variant::convert_construct(T&, int, mpl_::false_) [with T = const Lang::Elements::Expression, T0_ = double, T1 = std::basic_string, std::allocator >, T2 = boost::detail::variant::void_, T3 = boost::detail::variant::void_, T4 = boost::detail::variant::void_, T5 = boost::detail::variant::void_, T6 = boost::detail::variant::void_, T7 = boost::detail::vari

それがこの方法です:

template <typename T>

void convert_construct(
      T& operand
    , int
    , mpl::false_ = mpl::false_() // is_foreign_variant
    )
{
    // NOTE TO USER :
    // Compile error here indicates that the given type is not 
    // unambiguously convertible to one of the variant's types
    // (or that no conversion exists).
    //
    indicate_which(
          initializer::initialize(
              storage_.address()
            , operand
            )
        );
}</code>

Remember this error originates from the %= in the init_decl expression. The only variant in this expression is the one contained by the Expression object which is the expression rule's attribute value. The error seems to say that a variant (the type of object Expression contains) is trying to instantiate itself from an Expression, but I can't see this anywhere in the code. Anyway, I added cast operators to the Expression struct that exposes its underlying variant, but still I got the error.

The method that calls the method above is this:

template <typename T>

variant(const T& operand)
{
    convert_construct(operand, 1L);
}</code>

It seems like it's trying to call this method instead:

template <typename Variant>

void convert_construct(
      Variant& operand
    , long
    , mpl::true_// is_foreign_variant
    )
{
    convert_copy_into visitor(storage_.address());
    indicate_which(
          operand.internal_apply_visitor(visitor)
        );
}</code>

これは、このエラーの原因であるコンパイラの誤解ですか?

于 2010-08-27T18:22:46.233 に答える