Language: C++

#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cctype>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

std::vector<std::string> preprocess(const std::string &s, std::string &t) {
  int last='^';
  t.clear();
  std::vector<std::string> res;
  for (size_t i=0; i<s.length(); ++i) {
    if (isalpha(s[i])) {
      std::string cur(1, s[i]);
      while (++i < s.length() && isalpha(s[i])) {
        cur += s[i];
      }
      res.push_back(cur);
      t += res.size()+'0';
      if (i < s.length()) {
        t += s[i];
      }
    } else {
      t += s[i];
    }
  }
  assert(res.size() == 1 || res.size() == 2);
  return res;
}

enum Cond {
  A, NA,
  B, NB,
  AaB, NAoNB,
  NAaB, AoNB,
  AoB, NAaNB,
  NAoB, AaNB,
};

Cond not_cond(Cond x) {
  return Cond(int(x)^1);
}

Cond apply_cond(Cond x, int op, Cond y) {
  if (!(x == A || x == NA)) {
    std::swap(x, y);
  }
  if (op == '&') {
    if (x == A && y == B) return AaB;
    if (x == NA && y == B) return NAaB;
    if (x == A && y == NB) return AaNB;
    if (x == NA && y == NB) return NAaNB;
  } else if (op == '|') {
    if (x == A && y == B) return AoB;
    if (x == NA && y == B) return NAoB;
    if (x == A && y == NB) return AoNB;
    if (x == NA && y == NB) return NAoNB;
  }
  assert(false);
}

Cond parse(const std::string &s, size_t &i,
           const std::vector<std::string> &ops={"|&", ""}, size_t p=0) {

  if (ops[p].empty()) {
    if (s[i] == '(') {
      Cond tmp=parse(s, ++i, ops, 0);
      assert(s[i] == ')');
      ++i;
      return tmp;
    } else if (s[i] == '~') {
      Cond tmp=parse(s, ++i, ops, 0);
      return not_cond(tmp);
    } else if (s[i] == '1') {
      return A;
    } else if (s[i] == '2') {
      return B;
    }
  }

  Cond res=parse(s, i, ops, p+1);
  while (i < s.length()) {
    int op=s[i];
    if (!std::count(ops[p].begin(), ops[p].end(), op)) break;
    Cond tmp=parse(s, ++i, ops, p+1);
    apply_cond(res, op, tmp);
  }
  return res;
}

int main() {
  size_t N, M;
  scanf("%zu %zu", &N, &M);

  std::map<std::string, size_t> vars;
  for (size_t i=0; i<N; ++i) {
    char buf[512];
    scanf("%s", buf);
    std::string s=buf;
    std::string t;
    std::vector<std::string> lits=preprocess(s, t);
    fprintf(stderr, "t: %s\n", t.c_str());
    for (const auto &lit: lits) {
      if (vars.find(lit) != vars.end()) {
        size_t size=vars.size();
        vars.emplace(lit, size);
      }
    }
    size_t j=0;
    Cond cond=parse(t, j);

    // tsurai
  }

  //printf("%s\n", satisfiable(g)? "accept":"reject");
}

t: ~~(~1|2);
D: D.cpp:70: Cond parse(const string&, size_t&, const std::vector<std::__cxx11::basic_string<char> >&, size_t): Assertion `s[i] == ')'' failed.
Aborted (core dumped)



Compiler output:
a.cc:121:123: error: stray '`' in program
  121 | D: D.cpp:70: Cond parse(const string&, size_t&, const std::vector<std::__cxx11::basic_string<char> >&, size_t): Assertion `s[i] == ')'' failed.
      |                                                                                                                           ^
a.cc:121:135: warning: missing terminating ' character
  121 | D: D.cpp:70: Cond parse(const string&, size_t&, const std::vector<std::__cxx11::basic_string<char> >&, size_t): Assertion `s[i] == ')'' failed.
      |                                                                                                                                       ^
a.cc:121:135: error: missing terminating ' character
  121 | D: D.cpp:70: Cond parse(const string&, size_t&, const std::vector<std::__cxx11::basic_string<char> >&, size_t): Assertion `s[i] == ')'' failed.
      |                                                                                                                                       ^~~~~~~~~
a.cc:120:1: error: 't' does not name a type; did you mean 'tm'?
  120 | t: ~~(~1|2);
      | ^
      | tm
a.cc:121:2: error: found ':' in nested-name-specifier, expected '::'
  121 | D: D.cpp:70: Cond parse(const string&, size_t&, const std::vector<std::__cxx11::basic_string<char> >&, size_t): Assertion `s[i] == ')'' failed.
      |  ^
      |  ::
a.cc:121:1: error: 'D' does not name a type
  121 | D: D.cpp:70: Cond parse(const string&, size_t&, const std::vector<std::__cxx11::basic_string<char> >&, size_t): Assertion `s[i] == ')'' failed.
      | ^