Language: C++

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define all(c) c.begin(),c.end()
#define uni(c) c.erase(unique(c.begin(),c.end()),c.end())
#define pb push_back
using namespace std;

int expr(string& s, int& i);
int term(string& s, int& i);
int factor(string& s, int& i);
int number(string& s, int& i);


int expr(string& s, int& i) {
  int val = term(s, i);
  while(s[i] == '+' || s[i] == '-') {
    char op = s[i];
    i++;
  	if(!isdigit(s[i])){
  		i++;
  		int val2 = term(s, i);
  		if(val==1&&val2==0){
  			val=0;
  		}else{
  			val=1;
  		}
  	}else{
  	  int val2 = term(s, i);
    	if (op == '+') val |= val2;
  	}
  }
  return val;
}

int term(string& s, int& i) {
  int val = factor(s, i);
  while(s[i] == '*') {
    char op = s[i];
    i++;
    int val2 = factor(s, i);
    if (op == '*') val *= val2;
  }
  return val;
}

int factor(string& s, int& i) {
	int flag=0;
	if(s[i]=='-'){
		flag=1;
		i++;
	}
	if (isdigit(s[i])){
		if(flag)
			return flag^number(s, i);
			return number(s,i);
	}

  // ここで構文が正しければ s[i] == '(' となる
  i++; // '('を読み飛ばす
  int ret = expr(s, i);
  i++; // ')'を読み飛ばす
	if(flag)
	return flag^ret;
	return ret;
}

int number(string& s, int& i) {
  int n = s[i++] - '0';
  while(isdigit(s[i])) n = n*10 + s[i++] - '0';
  return n;
}

int main(){
	string s;
	while(cin>>s,s!="#"){
		int eq=0;
		string a,b;
		for(;s[eq]!='=';eq++);
		a=s.substr(0,eq),b=s.substr(eq+1,s.size()-eq);
		//cout<<a<<" "<<b<<endl;
		vector<char> ap;
		for(int i=0;i<s.size();i++){
			if(isalpha(s[i]))
				ap.pb(s[i]);
		}
		sort(all(ap));
		uni(ap);
		bool flag=true;
		for(int i=0;i<(1<<ap.size());i++){
			string x=a,y=b;
			for(int j=0;j<ap.size();j++){
				char c=ap[j];
				bool wh=false;
				if((1<<j)&i)
					wh=true;
				for(int k=0;k<x.size();k++){
					if(x[k]==c){
						if(wh)
							x[k]='1';
						else
							x[k]='0';
					}
				}
				for(int k=0;k<y.size();k++){
					if(y[k]==c){
						if(wh)
							y[k]='1';
						else
							y[k]='0';
					}
				}
			}
			
			
			cout<<x<<" "<<y<<endl;
			cout<<expr(x,0)<<"  "<<expr(y,0)<<endl;
			if(expr(x,0)!=expr(y,0)){
				cout<<"NO"<<endl;
				flag=false;
				break;
			}
			
		}
		if(flag)
			cout<<"YES"<<endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:118:38: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
  118 |                         cout<<expr(x,0)<<"  "<<expr(y,0)<<endl;
      |                                      ^
a.cc:16:26: note:   initializing argument 2 of 'int expr(std::string&, int&)'
   16 | int expr(string& s, int& i) {
      |                     ~~~~~^
a.cc:118:55: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
  118 |                         cout<<expr(x,0)<<"  "<<expr(y,0)<<endl;
      |                                                       ^
a.cc:16:26: note:   initializing argument 2 of 'int expr(std::string&, int&)'
   16 | int expr(string& s, int& i) {
      |                     ~~~~~^
a.cc:119:35: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
  119 |                         if(expr(x,0)!=expr(y,0)){
      |                                   ^
a.cc:16:26: note:   initializing argument 2 of 'int expr(std::string&, int&)'
   16 | int expr(string& s, int& i) {
      |                     ~~~~~^
a.cc:119:46: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
  119 |                         if(expr(x,0)!=expr(y,0)){
      |                                              ^
a.cc:16:26: note:   initializing argument 2 of 'int expr(std::string&, int&)'
   16 | int expr(string& s, int& i) {
      |                     ~~~~~^