Language: C++

#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <string>
#include <set>
#include <map>
using namespace std;

#define State string::const_iterator

class ParseError {};

vector<int> U;//mapを使った方が楽。
map<char, vector<int>> sets;

vector<int> expression(State &begin);
vector<int> com(State &begin);
vector<int> _set(State &begin);
vector<int> factor(State &begin);
inline void consume(State &begin, char expected);

vector<int> dif(vector<int> my_left, vector<int>my_right){
    vector<int> ret = {};
    std::set_difference(my_left.begin(), my_left.end(),
                        my_right.begin(), my_right.end(),
                        std::inserter(ret, ret.end()));
    return ret;
}

// 四則演算の式をパースして、その評価結果を返す。
vector<int> expression(State &begin) {
    vector<int> my_left = factor(begin);
    vector<int> ret = {};

    while(true){
        if(*begin == 'u'){
            consume(begin, 'u');
            vector<int> my_right = factor(begin);
            set_union(std::begin(my_left), std::end(my_left), std::begin(my_right), std::end(my_right), std::inserter(ret, std::end(ret)));
        }
        else if(*begin == 'i'){
            consume(begin, 'i');
            vector<int> my_right = factor(begin);
            set_intersection(std::begin(my_left), std::end(my_left), std::begin(my_right), std::end(my_right), std::inserter(ret, std::end(ret)));
        }
        else if(*begin == 'd'){
            consume(begin, 'd');
            vector<int> my_right = factor(begin);
            ret = dif(my_left, my_right);
        }
        else if(*begin == 's'){
            consume(begin, 's');
            vector<int> my_right = factor(begin);
            set_symmetric_difference(std::begin(my_left), std::end(my_left), std::begin(my_right), std::end(my_right), std::inserter(ret, std::end(ret)));
        }
        else{
            break;
        }
    }

    return ret;

}

// 乗算除算の式をパースして、その評価結果を返す。
vector<int> com(State &begin) {

    vector<int> ret = {};
    if(*begin == 'c'){
        consume(begin, 'c');
        vector<int> v = factor(begin);
        sort(v.begin(), v.end());
        ret = dif(U, v);
    }
    else {
        ret = sets[*begin];
        sort(ret.begin(), ret.end());
        begin++;
    }

    return ret;
}

// 数字の列をパースして、その数を返す。
vector<int> _set(State &begin) {
    vector<int> ret;

    if(*begin == 'A'){
        consume(begin, 'A');
        ret = A;
    }
    else if(*begin == 'B'){
        consume(begin, 'B');
        ret = B;
    }
    else if(*begin == 'C'){
        consume(begin, 'C');
        ret = C;
    }
    else if(*begin == 'D'){
        consume(begin, 'D');
        ret = D;
    }
    else if(*begin == 'E'){
        consume(begin, 'E');
        ret = E;
    }

    return ret;
}

// 括弧か数をパースして、その評価結果を返す。
vector<int> factor(State &begin) {
    if (*begin == '(') {
        consume(begin, '('); // '('を飛ばす。
        vector<int> ret = expression(begin);
        consume(begin, ')'); // ')'を飛ばす。
        return ret;
    } else {
        return com(begin);
    }
}

// beginがexpectedを指していたらbeginを一つ進める。
inline void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'"
             << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        throw ParseError();
    }
}

int main() {

    while(true) {

        set<int> u;

        while (true) {

            char se;
            int n;

            cin >> se >> n;

            if (se == 'R') {
                break;
            }
            else{
                for(int i=0; i<n; i++){
                    int input;
                    cin >> input;
                    sets[se].push_back(input);
                    u.insert(input);
                }
            }
        }

        for(pair<char,vector<int>> v : sets){
            sort(v.second.begin(), v.second.end());
            cout << v.first << " : ";
            for(int num : v.second){
                cout << num << " ";
            }
            cout << endl;
        }

        for (int num : u) {
            U.push_back(num);
        }

        string formula;

        cin >> formula;

        if(formula == "shutdown"){
            break;
        }

        State begin = formula.begin();

        vector<int> ans = expression(begin);

        if (ans.size() == 0) {
            cout << "NULL" << endl;
        } else {
            cout << ans[0];

            for (int i = 1; i < ans.size(); i++) {
                cout << " " << ans[i];
            }

            cout << endl;
        }

    }

    return 0;
}


Compiler output:
a.cc: In function 'std::vector<int> _set(std::__cxx11::basic_string<char>::const_iterator&)':
a.cc:91:15: error: 'A' was not declared in this scope
   91 |         ret = A;
      |               ^
a.cc:95:15: error: 'B' was not declared in this scope
   95 |         ret = B;
      |               ^
a.cc:99:15: error: 'C' was not declared in this scope
   99 |         ret = C;
      |               ^
a.cc:103:15: error: 'D' was not declared in this scope
  103 |         ret = D;
      |               ^
a.cc:107:15: error: 'E' was not declared in this scope
  107 |         ret = E;
      |               ^