Language: C++

#include<iostream>
#include<string>
#include<set>
#include<iterator>
#include<algorithm>
#include<vector>

using namespace std;

typedef basic_string<bool> BS;
const BS T=BS(1,true);
const BS F=BS(1,false);

char str[999];
char *p;

struct Cell{
  Cell *l,*r;
  BS bs;
  set<BS> sbs;
  int num,den;
  Cell():l(),r(),num(),den(1){
    while(*p==' '){
      p++;
    }
    if(*p=='x'){
      p++;
      bs=T+F;
    }else{
      p++;
      l=new Cell();
      r=new Cell();
      if(*r>*l){
	swap(l,r);
      }
      vector<BS> u,i;
      set_union(begin(l->sbs),end(l->sbs),begin(r->sbs),end(r->sbs),back_inserter(u));
      set_intersection(begin(l->sbs),end(l->sbs),begin(r->sbs),end(r->sbs),back_inserter(i));
      num=i.size();
      den=u.size();
      sbs=set<BS>(begin(u),end(u));
      bs=T+l->bs+r->bs+F;
    }
    p++;
    sbs.insert(bs);
  }
  bool operator>(const Cell &c)const{
    if(num*c.den!=c.num*den){
      return num*c.den<c.num*den;
    }else if(l==nullptr&&c.l==nullptr){
      return false;
    }else if(*l>*c.l||*c.l>*l){
      return *l>*c.l;
    }else{
      return *r>*c.r;
    }
  }
  void print(bool left){
    if(l==nullptr){
      cout<<'x';
    }else{
    cout<<'(';
    if(!left){
      swap(l,r);
    }
    l->print(true);
    r->print(false);
  }
  ~Cell(){
    delete l;
    delete r;
  }
};


int main(){
  while(cin.getline(str,999),str[0]!='0'){
    p=str;
    Cell c;
    c.print(true);
    cout<<endl;
  }
}

Compiler output:
a.cc:83:2: error: expected '}' at end of input
   83 | }
      |  ^
a.cc:17:12: note: to match this '{'
   17 | struct Cell{
      |            ^
a.cc: In member function 'void Cell::print(bool)':
a.cc:69:3: error: no match for 'operator~' (operand type is 'Cell')
   69 |   ~Cell(){
      |   ^~~~~~~
In file included from /usr/include/c++/14/bits/memory_resource.h:38,
                 from /usr/include/c++/14/string:68,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/cstddef:151:3: note: candidate: 'constexpr std::byte std::operator~(byte)'
  151 |   operator~(byte __b) noexcept
      |   ^~~~~~~~
/usr/include/c++/14/cstddef:151:18: note:   no known conversion for argument 1 from 'Cell' to 'std::byte'
  151 |   operator~(byte __b) noexcept
      |             ~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:99:3: note: candidate: 'constexpr std::_Ios_Fmtflags std::operator~(_Ios_Fmtflags)'
   99 |   operator~(_Ios_Fmtflags __a) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:99:27: note:   no known conversion for argument 1 from 'Cell' to 'std::_Ios_Fmtflags'
   99 |   operator~(_Ios_Fmtflags __a) _GLIBCXX_NOTHROW
      |             ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:149:3: note: candidate: 'constexpr std::_Ios_Openmode std::operator~(_Ios_Openmode)'
  149 |   operator~(_Ios_Openmode __a) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:149:27: note:   no known conversion for argument 1 from 'Cell' to 'std::_Ios_Openmode'
  149 |   operator~(_Ios_Openmode __a) _GLIBCXX_NOTHROW
      |             ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ios_base.h:196:3: note: candidate: 'constexpr std::_Ios_Iostate std::operator~(_Ios_Iostate)'
  196 |   operator~(_Ios_Iostate __a) _GLIBCXX_NOTHROW
      |   ^~~~~~~~
/usr/include/c++/14/bits/ios_base.h:196:26: note:   no known conversion for argument 1 from 'Cell' to 'std::_Ios_Iostate'
  196 |   operator~(_Ios_Iostate __a) _GLIBCXX_NOTHROW
      |             ~~~~~~~~~~~~~^~~
a.cc: In member function 'int Cell::main()':
a.cc:83:1: warning: no return statement in function returning non-void [-Wreturn-type]
   83 | }
      | ^
a.cc: At global scope:
a.cc:83:2: error: expected unqualified-id at end of input
   83 | }
      |  ^