Language: C++

#include<string>
#define MAX 13
using namespace std;
bool o;
void rec(string s){
  if(!o) return;
  //cout << s << endl;
  bool f;
  int p;
  while(s.find("-0")!=-1){
    p=s.find("-0");
    s[p]='1';s[p+1]=' ';
    f=true;
  }
  while(s.find("-1")!=-1){
    p=s.find("-1");
    s[p]='0';s[p+1]=' ';
    f=true;
  }
  while(s.find("(0*0)")!=-1){
    p=s.find("(0*0)");
    s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
    f=true;
  }
  while(s.find("(0*1)")!=-1){
    p=s.find("(0*1)");
    s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
    f=true;
  }
  while(s.find("(1*0)")!=-1){
    p=s.find("(1*0)");
    s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
    f=true;
  }
  while(s.find("(1*1)")!=-1){
    p=s.find("(1*1)");
    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
    f=true;
  }
  while(s.find("(0+0)")!=-1){
    p=s.find("(0+0)");
    s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
    f=true;
  }
  while(s.find("(0+1)")!=-1){
    p=s.find("(0+1)");
    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
    f=true;
  }
  while(s.find("(1+0)")!=-1){
    p=s.find("(1+0)");
    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
    f=true;
  }
  while(s.find("(1+1)")!=-1){
    p=s.find("(1+1)");
    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';
    f=true;
  }
  while(s.find("(0->0)")!=-1){
    p=s.find("(0->0)");
    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';s[p+5]=' ';
    f=true;
  }
  while(s.find("(0->1)")!=-1){
    p=s.find("(0->1)");
    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';s[p+5]=' ';
    f=true;
  }
  while(s.find("(1->0)")!=-1){
    p=s.find("(1->0)");
    s[p]='0';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';s[p+5]=' ';
    f=true;
  }
  while(s.find("(1->1)")!=-1){
    p=s.find("(1->1)");
    s[p]='1';s[p+1]=' ';s[p+2]=' ';s[p+3]=' ';s[p+4]=' ';s[p+5]=' ';
    f=true;
  }
  if(f){
    string b;
    for(int i=0;i<s.size();i++) if(s[i]!=' ') b+=s[i];
    rec(b);
  }else{
    if(s[0]!=s[2]) o=false;
    return;
  }
}
void init(int n,string s){
  int i,j;
  for(i=0;i<s.size();i++){
    for(j=0;j<=MAX;j++){
      if(s[i]=='a'+j) s[i]='0'+(n>>j&1);
      if(s[i]=='T') s[i]='1';
      if(s[i]=='F') s[i]='0';
    }
  }
  rec(s);
}
int main(){
  string s;
  while(cin >> s,s!="#"){
    o=true;
    int i;
    for(i=0;i<(1<<MAX);i++)
      init(i,s);
    cout << (o?"YES":"NO") << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:102:9: error: 'cin' was not declared in this scope
  102 |   while(cin >> s,s!="#"){
      |         ^~~
a.cc:2:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    1 | #include<string>
  +++ |+#include <iostream>
    2 | #define MAX 13
a.cc:107:5: error: 'cout' was not declared in this scope
  107 |     cout << (o?"YES":"NO") << endl;
      |     ^~~~
a.cc:107:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:107:31: error: 'endl' was not declared in this scope
  107 |     cout << (o?"YES":"NO") << endl;
      |                               ^~~~
a.cc:2:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    1 | #include<string>
  +++ |+#include <ostream>
    2 | #define MAX 13