Language: C++

#include <iostream>
#include <string>

using namespace std;

struct node_t
{
	virtual int eval(int p, int q, int r) = 0;
};

struct lit : public node_t
{
	const int val;

	lit(int v) : val(v) { }
	int eval(int p, int q, int r) { return val; }
};

struct var : public node_t
{
	const char name;

	var(char name) : name(name) { }
	int eval(int p, int q, int r)
	{
		return name == 'P' ? p : (name == 'Q' ? q : r);
	}
};

struct not : public node_t
{
	node_t *x;

	not(node_t *x) : x(x) { }
	~not()
	{
		delete x;
	}
	int eval(int p, int q, int r)
	{
		return 2 - x->eval(p, q, r);
	}
};

struct or : public node_t
{
	node_t *x, *y;

	or(node_t *x, node_t *y) : x(x), y(y) { }
	~or()
	{
		delete x;
		delete y;
	}
	int eval(int p, int q, int r)
	{
		return max(x->eval(p, q, r), y->eval(p, q, r));
	}
};

struct and : public node_t
{
	node_t *x, *y;

	and(node_t *x, node_t *y) : x(x), y(y) { }
	~and()
	{
		delete x;
		delete y;
	}
	int eval(int p, int q, int r)
	{
		return min(x->eval(p, q, r), y->eval(p, q, r));
	}
};

static string s;
static int p;

bool end() { return p >= s.length(); }
char peek() { return s[p]; }
void succ() { if (!end()) p++; }

node_t *fomula()
{
	char c = peek();
	if ('0' <= c && c <= '2')
	{
		succ();
		return new lit(c - '0');
	}
	else if ('P' <= c && c <= 'R')
	{
		succ();
		return new var(c);
	}
	else if (c == '-')
	{
		succ();
		return new not(fomula());
	}
	else if (c == '(')
	{
		succ();
		node_t *x = fomula();
		char op = peek(); succ();
		node_t *y = fomula();
		succ(); // ')'
		if (op == '+') return new or(x, y);
		else return new and(x, y);
	}
}

node_t *parse_fomula()
{
	p = 0;
	return fomula();
}

int main()
{
	while(cin>>s, s != ".")
	{
		node_t *e = parse_fomula();

		int c = 0;
		for (int p = 0; p <= 2; p++)
		{
			for (int q = 0; q <= 2; q++)
			{
				for (int r = 0; r <= 2; r++)
				{
					if (e->eval(p, q, r) == 2) c++;
				}
			}
		}
		cout << c << endl;

		delete e;
	}
	return 0;
}

Compiler output:
a.cc:30:8: error: expected identifier before 'not' token
   30 | struct not : public node_t
      |        ^~~
a.cc:30:8: error: expected unqualified-id before 'not' token
a.cc:45:8: error: expected identifier before 'or' token
   45 | struct or : public node_t
      |        ^~
a.cc:45:8: error: expected unqualified-id before 'or' token
a.cc:61:8: error: expected identifier before 'and' token
   61 | struct and : public node_t
      |        ^~~
a.cc:61:12: error: expected unqualified-id before ':' token
   61 | struct and : public node_t
      |            ^
a.cc: In function 'node_t* fomula()':
a.cc:100:28: error: expected type-specifier before 'not' token
  100 |                 return new not(fomula());
      |                            ^~~
a.cc:100:27: error: expected ';' before 'not' token
  100 |                 return new not(fomula());
      |                           ^~~~
      |                           ;
a.cc:109:43: error: expected type-specifier before 'or' token
  109 |                 if (op == '+') return new or(x, y);
      |                                           ^~
a.cc:110:33: error: expected type-specifier before 'and' token
  110 |                 else return new and(x, y);
      |                                 ^~~