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]

감사합니다.

P. 코드를 올바르게 표시 할 수 없으므로 여기에 일반 텍스트 버전이 있습니다. http://freetexthost.com/a3smzx0zk5

P.P.S. 언급 할만한 몇 가지 정보가 있습니다. "else" >>을 제거하고 > statement>> statement으로 변경하면 작동하지만 "else" >> statement은 구문대로 축소해야합니다. 명시 적으로 "else"를 qi :: lit로 만들면 도움이되지 않습니다.

답변

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) ; 

+0

좋은 생각이지만 여전히 작동하지 않습니다. 작동하면 다른 사람을 제거, 그 유일한 단서가 있습니다. – Dave

+0

좋아, 그럼 내가 컴파일 할 수있는 작은 자체 테스트를보고 싶습니다. 그렇지 않으면 무엇이 잘못되었는지를 말하는 것이 거의 불가능합니다. – hkaiser

0

어, 편집하거나 댓글을 달 수없는 것처럼 보입니다. 답변으로 게시해야합니다.

규칙을 if 문 규칙과 if-else 문 규칙으로 분할하여 문제를 해결했습니다. 그러나이 문제는 init 선언에 대한 나의 정의에서 비롯된 것입니다.

real_literal %= double_ ;

이전

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

같은 문제

literal %= real_literal | string_literal ;

expression %= literal ;

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


init_decl %= identifier >> -('=' >> expression) ;

. 그러나 처음에는 전혀 문제를 조사하지 않았습니다.

템플릿 >

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> 

이 오류가 init_decl 발현의 % =로부터 유래 된 유형 이름 기억 < T :이 방법

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

. 이 표현식의 유일한 변형은 표현식 규칙의 속성 값인 Expression 객체에 포함 된 변형입니다. 이 오류는 표현식에서 인스턴스를 생성하려고하는 variant (객체 Expression의 유형이 포함)가 코드의 어느 부분에서도 볼 수 없다고 말하는 것 같습니다. 어쨌든, 기본 변형을 노출하는 표현식 구조체에 캐스트 연산자를 추가했지만 여전히 오류가 발생했습니다.

방법 위의 호출 방법은 이것이다 :

템플릿 < 유형 이름 변형 :

템플릿 < 유형 이름의 T 대신이 메서드를 호출하려고 것 같다 >

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

>

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> 

이 오류의 원인이 컴파일러 오해입니까?