Language: C++

#include <iostream>
#include <string>
#include <set>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>

using namespace std;

typedef map<char, set<int> > mapset;

set<int> atom(string&, mapset&, int&);
set<int> block(string&, mapset&, int&);
set<int> unite(set<int>&, set<int>&);
set<int> intersection(set<int>&, set<int>&);
set<int> difference(set<int>&, set<int>&);
set<int> symmetric_difference(set<int>&, set<int>&);
set<int> parse(string&, mapset&, int&);
set<int> complement(mapset&, set<int>&);

set<int> atom(string &expr, mapset &sets, int &k) {
    return sets[expr[k++]];
}

set<int> block(string &expr, mapset &sets, int &k) {
    if (expr[k] == '(') {
        k ++;
        return parse(expr, sets, k++);
    } else if (expr[k] == 'c') {
        k ++;
        return complement(sets, block(expr, sets, k));
    }
    return atom(expr, sets, k);
}

set<int> unite(set<int> &s1, set<int> &s2) {
    set<int> ret(s1);
    for (set<int>::iterator it=s2.begin(); it!=s2.end(); ++it) {
        ret.insert(*it);
    }
    return ret;
}

set<int> intersection(set<int> &s1, set<int> &s2) {
    set<int> ret;
    for (set<int>::iterator it=s2.begin(); it!=s2.end(); ++it) {
        if (s1.find(*it) != s1.end()) {
            ret.insert(*it);
        }
    }
    return ret;
}

set<int> difference(set<int> &s1, set<int> &s2) {
    set<int> ret(s1);
    for (set<int>::iterator it=s2.begin(); it!=s2.end(); ++it) {
        ret.erase(*it);
    }
    return ret;
}

set<int> symmetric_difference(set<int> &s1, set<int> &s2) {
    return unite(difference(s1, s2), difference(s2, s1));
}

set<int> complement(mapset &sets, set<int> &s1) {
    set<int> U;
    for (mapset::iterator it=sets.begin(); it!=sets.end(); ++it) {
        U = unite(U, it->second);
    }
    return difference(U, s1);
}

set<int> parse(string &expr, mapset &sets, int &k) {
    set<int> v1 = block(expr, sets, k);
    while (k < (int)expr.size() && expr[k] != ')') {
        char op = expr[k++];
        set<int> v2 = block(expr, sets, k);
        if (op == 'u') {
            v1 = unite(v1, v2);
        } else if (op == 'i') {
            v1 = intersection(v1, v2);
        } else if (op == 'd') {
            v1 = difference(v1, v2);
        } else if (op == 's') {
            v1 = symmetric_difference(v1, v2);
        }
    }
    return v1;
}

void solve(string &expr, mapset &sets) {
    int k = 0;
    set<int> st = parse(expr, sets, k);
    if (st.empty()) {
        cout << "NULL" << endl;
        return ;
    }
    for (set<int>::iterator it=st.begin(); it!=st.end(); ++it) {
        cout << (it == st.begin() ? "" : " ") << *it;
    }
    cout << endl;
}

int main() {
    char c; int k;
    map<char, set<int> > sets;
    while (cin >> c >> k) {
        if (c != 'R') {
            set<int> st; int t;
            for (int i=0; i<k; ++i) {
                cin >> t;
                st.insert(t);
            }
            sets[c] = st;
        } else {
            string expr;
            cin >> expr;
            solve(expr, sets);

            sets.clear();
        }
    }
    return 0;
}

Compiler output:
a.cc: In function 'std::set<int> block(std::string&, mapset&, int&)':
a.cc:29:35: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
   29 |         return parse(expr, sets, k++);
      |                                  ~^~
a.cc:19:34: note:   initializing argument 3 of 'std::set<int> parse(std::string&, mapset&, int&)'
   19 | set<int> parse(string&, mapset&, int&);
      |                                  ^~~~
a.cc:32:38: error: cannot bind non-const lvalue reference of type 'std::set<int>&' to an rvalue of type 'std::set<int>'
   32 |         return complement(sets, block(expr, sets, k));
      |                                 ~~~~~^~~~~~~~~~~~~~~
a.cc:20:30: note:   initializing argument 2 of 'std::set<int> complement(mapset&, std::set<int>&)'
   20 | set<int> complement(mapset&, set<int>&);
      |                              ^~~~~~~~~
a.cc: In function 'std::set<int> symmetric_difference(std::set<int>&, std::set<int>&)':
a.cc:64:28: error: cannot bind non-const lvalue reference of type 'std::set<int>&' to an rvalue of type 'std::set<int>'
   64 |     return unite(difference(s1, s2), difference(s2, s1));
      |                  ~~~~~~~~~~^~~~~~~~
a.cc:37:26: note:   initializing argument 1 of 'std::set<int> unite(std::set<int>&, std::set<int>&)'
   37 | set<int> unite(set<int> &s1, set<int> &s2) {
      |                ~~~~~~~~~~^~