Language: C++


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <complex>
#include <cctype>
#include <cassert>

using namespace std;

int n;
string str;
int cur;

int digit(){
	assert(isdigit(S[cur]));
	int n = S[cur] - '0';
	cur++;
	return n;
}

int number(){
	int n = digit();
	while(cur < S.size() && isdigit(S[cur])){
		n = n * 10 + digit();
	}
	return n;
}

int expression(){
	int sum = term();
	while(cur < S.size() && (S[cur] == '+' || S[cur] == '-'){
		char op = S[cur];
		cur++;
		int b = term();
		if(op == '+') sum += b;
		else sum -= b;
	}
	
	return sum;
	
}

int term(){
	int sum = factor();
	while(cur < S.size() && (S[cur] == '*' || S[cur] == '/'){
		char op = S[cur];
		cur++;
		int b = factor();
		if(op == '*') sum *= b;
		else sum /= b;
	}
}

int factor(){
	if (S[cur] != ???(???) return number();
	cur++;
	int n = expression();
	cur++;
	return n;	
}


int main(void){

	cin >> n;

	for(int i = 0; i < n; i++){
		cur = 0;
		cin >> str;
		str.resize(str.size()-1);
		cout << expression() << endl;
	}
	
    return 0;
}

Compiler output:
a.cc:64:24: warning: trigraph ??( ignored, use -trigraphs to enable [-Wtrigraphs]
   64 |         if (S[cur] != ???(???) return number();
a.cc:64:28: warning: trigraph ??) ignored, use -trigraphs to enable [-Wtrigraphs]
In file included from /usr/include/c++/14/cassert:44,
                 from a.cc:15:
a.cc: In function 'int digit()':
a.cc:24:24: error: 'S' was not declared in this scope
   24 |         assert(isdigit(S[cur]));
      |                        ^
a.cc: In function 'int number()':
a.cc:32:21: error: 'S' was not declared in this scope
   32 |         while(cur < S.size() && isdigit(S[cur])){
      |                     ^
a.cc: In function 'int expression()':
a.cc:39:19: error: 'term' was not declared in this scope; did you mean 'tm'?
   39 |         int sum = term();
      |                   ^~~~
      |                   tm
a.cc:40:21: error: 'S' was not declared in this scope
   40 |         while(cur < S.size() && (S[cur] == '+' || S[cur] == '-'){
      |                     ^
a.cc:40:65: error: expected ')' before '{' token
   40 |         while(cur < S.size() && (S[cur] == '+' || S[cur] == '-'){
      |              ~                                                  ^
      |                                                                 )
a.cc: In function 'int term()':
a.cc:53:19: error: 'factor' was not declared in this scope
   53 |         int sum = factor();
      |                   ^~~~~~
a.cc:54:21: error: 'S' was not declared in this scope
   54 |         while(cur < S.size() && (S[cur] == '*' || S[cur] == '/'){
      |                     ^
a.cc:54:65: error: expected ')' before '{' token
   54 |         while(cur < S.size() && (S[cur] == '*' || S[cur] == '/'){
      |              ~                                                  ^
      |                                                                 )
a.cc:61:1: warning: no return statement in function returning non-void [-Wreturn-type]
   61 | }
      | ^
a.cc: In function 'int factor()':
a.cc:64:13: error: 'S' was not declared in this scope
   64 |         if (S[cur] != ???(???) return number();
      |             ^
a.cc:64:23: error: expected primary-expression before '?' token
   64 |         if (S[cur] != ???(???) return number();
      |                       ^
a.cc:64:24: error: expected primary-expression before '?' token
   64 |         if (S[cur] != ???(???) return number();
      |                        ^
a.cc:64:25: error: expected primary-expression before '?' token
   64 |         if (S[cur] != ???(???) return number();
      |                         ^
a.cc:64:27: error: expected primary-expression before '?' token
   64 |         if (S[cur] != ???(???) return number();
      |                           ^
a.cc:64:28: error: expected primary-expression before '?' token
   64 |         if (S[cur] != ???(???) return number();
      |                            ^
a.cc:64:29: error: expected primary-expression before '?' token
   64 |         if (S[cur] != ???(???) return number();
      |                             ^
a.cc:64:30: error: expected primary-expression before ')' token
   64 |         if (S[cur] != ???(???) return number();
      |                              ^
a.cc:64:30: error: expected ':' before ')' token
   64 |         if (S[cur] != ???(???) return number();
      |                              ^
      |                              :
a.cc:64:30: error: expected primary-expression before ')' token
a.cc:64:30: error: expected ':' before ')' token
   64 |         if (S[cur] != ???(???) return number();
      |                              ^
      |                              :
a.cc:64:30: error: expected primary-expression before ')' token
a.cc:64:30: error: expected ':' before ')' token
   64 |         if (S[cur] != ???(???) return number();
      |                              ^
      |                              :
a.cc:64:30: error: expected primary-expression before ')' token
a.cc:64:31: error: expected ':' before 'return'
   64 |         if (S[cur] != ???(???) return number();
      |                               ^~~~~~~
      |                               :
a.cc:64:32: error: expected primary-expression before 'return'
   64 |         if (S[cur] != ???(???) return number();
      |                                ^~~~~~
a.cc:64:31: error: expected ':' before 'return'
   64 |         if (S[cur] != ???(???) return number();
      |                               ^~~~~~~
      |                               :
a.cc:64:32: error: expected primary-expression before 'return'
   64 |         if (S[cur] != ???(???) return number();
      |                                ^~~~~~
a.cc:64:31: error: expected ':' before 'return'
   64 |         if (S[cur] != ???(???) return number();
      |                               ^~~~~~~
      |                               :
a.cc:64:32: error: expected primary-expression before 'return'
   64 |         if (S[cur] != ???(???) return number();
      |                                ^~~~~~
a.cc:64:31: error: expected ')' before 'return'
   64 |         if (S[cur] != ???(???) return number();
      |            ~                  ^~~~~~~
      |                               )