비교 연산자 (wihtout 논리 연산자 (예 : |, &) 만 사용하여 a = b & s < 9와 같은 부울 식을 평가하고 싶습니다. 그리고!).상위 노드에서 자식 노드 (잎)에 액세스하는 방법
=
/\
/ \
a b
또는
&
/\
/ \
= <
/\ /\
/ \/\
a b s 9
잎 노드
이 값은 다음과 같습니다 우리는 다음과 같은 AST를 가질 수 있습니다. leave 노드의 부모는 항상 =,! =, <,>,> =, < =과 같은 비교 연산자입니다. 비교 노드의 부모는 논리 연산자 |, & 및!입니다. 부모 노드에서 값 노드 (잎)에 액세스하고이 값을 다른 함수 (나중에 구현 됨)에 전달하고 싶습니다. 구문 분석 단계는 정상입니다.상위 노드에서 값 노드 (잎)에 액세스하는 방법. 내가에서 예제를 사용하고 있습니다 :
struct eval : boost::static_visitor<bool> { eval() {} // bool operator()(const var& v) const { std::cout<<"feuille:\n"<<v<<std::endl; return true; } bool operator()(const binop<op_and>& b) const { recurse(b.oper1) && recurse(b.oper2); } bool operator()(const binop<op_or>& b) const { recurse(b.oper1) || recurse(b.oper2); } bool operator()(const unop<op_not>& u) const { return !recurse(u.oper1); } //------------adding others operators---------------------------- bool operator()(const binop<op_equal>& u) const { // will be implemented later return true; } bool operator()(const binop<op_not_equal>& u) const { // will be implemented later return true; } bool operator()(const binop<op_less>& u) const { // will be implemented later return true; } bool operator()(const binop<op_less_equal>& u) const { // will be implemented later return true; } bool operator()(const binop<op_greater>& u) const { // will be implemented later return true; } bool operator()(const binop<op_greater_equal>& u) const { // will be implemented later return true; }감사합니다 : How to calculate boolean expression in Spirit
및 Boolean expression (grammar) parser in c++ 이 이러한 링크에서 가져온 평가 코드입니다. 어떤 제안이라도 환영합니다.
을 의미 할 수 있습니다. 어떻게 부울 표현식 예제가 유니 코드를 지원할 수 있는지 궁금합니다. 나는 다음과 같이 시도했다 : – user2891256
도움이되었다! 어떻게 부울 표현식 예제가 유니 코드를 지원할 수 있는지 궁금합니다. 나는 템플리트 대신에 템플릿을 시도했다. 고맙습니다. –
user2891256
선장 교체는 ecoding (IIRC'standard_wide'는 _namespace_입니까?)으로 대체 할 수 없습니다. 대신, [정보 둘러보기] (http://stackoverflow.com/search?tab=votes&q=%5bboost-spirit%5d%20OR%20%5bboost-spirit-qi%5d%20unicode). 유니 코드는 부울 표현식과 거의 관련이 없습니다. 그 문제에 대해서'wstring'도 마찬가지입니다. [이] (http://stackoverflow.com/questions/13679669/how-to-use-boostspirit-to-parse-utf-8/15820479#15820479) 매우 명확하게 보였습니다 – sehe