Language: C++

#include<string>
#define MAX 11
using namespace std;
bool o;
void rec(string s){
  if(!o) return;
  //cout << s << endl;
  while(1){
    bool f=false;
    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];
      s=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);
  if(!o) return;
}
int main(){
  string s;
  while(cin >> s,s!="#"){
    o=true;
    int i;
    for(i=0;i<(1<<MAX);i++)
      if(o) init(i,s);
      else break;
    cout << (o?"YES":"NO") << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:108:9: error: 'cin' was not declared in this scope
  108 |   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 11
a.cc:114:5: error: 'cout' was not declared in this scope
  114 |     cout << (o?"YES":"NO") << endl;
      |     ^~~~
a.cc:114:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:114:31: error: 'endl' was not declared in this scope
  114 |     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 11