Go: package main

import (
	"bufio"
	"fmt"
	"go/token"
	"go/types"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())
	for i := 0; i < n; i++ {
		stdin.Scan()
		exp := strings.TrimRight(stdin.Text(), "=")
		res, _ := types.Eval(token.NewFileSet(), nil, token.NoPos, exp)
		fmt.Println(res.Value)
	}
}

C++: #include <iostream>
#include <vector>

using namespace std;

int eval(const string & expr) {
	int left = 0;
	int right = 0;
	int mdtemp = 0;
	int ev_idx = 0;
	int sign = 1; // 1=+, -1=-
	char c, cc;

	// 項の処理
	while((c = expr[ev_idx++]) != '=' && c != '\0') {
		if(c == '+' || c == '-') {
			left += sign * right;
			right = 0;
			if(c == '+') sign = 1;
			else sign = -1;
		} else if(c == '*' || c == '/') { // if mul,div
			mdtemp = 0;
			while(1) {
				if((cc = expr[ev_idx++]) == '=' || cc == '\0' || cc == '+' || cc == '-' || cc == '*' || cc == '/') {
					ev_idx--;
					break;
				}
				if(cc == '(') {
					int clen = 0;
					int cstrt = ev_idx;
					while(expr[ev_idx++] != ')') clen++;
					string ceval = expr.substr(cstrt, clen);
					mdtemp = eval(ceval);
				} else {
					mdtemp *= 10;
					mdtemp += (int)(cc - '0');
				}
			}
			if(c == '*') right *= mdtemp;
			else right /= mdtemp;
		} else if(c == '(') {
			int clen = 0;
			int cstrt = ev_idx;
			while(expr[ev_idx++] != ')') clen++;
			string ceval = expr.substr(cstrt, clen);
			right = eval(ceval);
		} else { // if numbers
			right *= 10;
			right += (int)(c - '0');
		}
	}
	left += sign * right;
	
	return left;
}

int main() {
	int n;
	cin >> n;
	
	vector<int> anss(n);

	for(int i=0;i<n;i++) {
		string expr;
		cin >> expr;
		int ans;
		ans = eval(expr);
		anss[i] = ans;
	}
	for(auto it = anss.begin(); it != anss.end(); it++) {
		cout << *it << endl;
	}
	
	return 0;
}

C++: #if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

string S;
size_t cur;

char readchar() {
  assert(cur < S.size());
  return S[cur++];
}
char peek() {
  assert(cur < S.size());
  return S[cur];
}
int digit() {
  assert(isdigit(peek()));
  int n = readchar() - '0';
  return n;
}
int number() {
  int n = digit();
  while (cur < S.size() && isdigit(peek()))
    n = n*10 + digit();
  return n;
}
int expression();
int factor() {
  if (peek() != '(')
    return number();
  cur += 1;
  int n = expression();
  assert(peek() == ')');
  cur += 1;
  return n;
}
int term() {
  int a = factor();
  while (cur < S.size() && (peek() == '*' || peek() == '/')) {
    char op = readchar();
    int b = factor();
    if (op == '*')
      a *= b;
    else
      a /= b;
  }
  return a;
}
int expression() {
  int a = term();
  while (cur < S.size() && (peek() == '+' || peek() == '-')) {
    char op = readchar();
    int b = term();
    if (op == '+')
      a += b;
    else
      a -= b;
  }
  return a;
}

int main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) {
    cur = 0;
    cin >> S;
    S.resize(S.size()-1);
    cout << expression() << endl;
  }
}

C++: #include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

typedef string::const_iterator State;

int expression(State &begin);
int term(State &begin);
int number(State &begin);
int factor(State &begin);

// 四則演算の式をパースして、その評価結果を返す
int expression(State &begin){
    int ret = term(begin);
    while(1){
        if(*begin == '+'){
            begin++;
            ret += term(begin);
        }else if(*begin == '-'){
            begin++;
            ret -= term(begin);
        }else{
            break;
        }
    }
    return ret;
}

// 乗算除算の式をパースして、その評価結果を返す
int term(State &begin){
    int ret = factor(begin);
    while(1){
        if(*begin == '*'){
            begin++;
            ret *= factor(begin);
        }else if(*begin == '/'){
            begin++;
            ret /= factor(begin);
        }else{
            break;
        }
    }
    return ret;
}

// 括弧か数をパースして、その評価を返す
int factor(State &begin){
    if(*begin == '('){
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    }else{
        return number(begin);
    }
}

// 数字の列をパースして、その数を返す
int number(State &begin){
    int ret = 0;
    while(isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    cin.ignore();
    for(int i=0; i<N; i++){
        string S;
        getline(cin,S);
        State begin = S.begin();
        int ans = expression(begin);
        cout << ans << enld;
    }
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <utility>
using namespace std;

typedef pair<int, int> Pair;

int _;
int n;
char buf[11451419];

Pair EvalElem(int pos);
Pair EvalTerm(int pos);
Pair EvalExp(int pos);

Pair EvalElem(int pos) {
  char c = buf[pos];

  if ('0' <= c && c <= '9') {
    char *next;
    int res = strtol(buf+pos, &next, 10);
    return Pair(res, next-buf);
  }

  return Pair(-1, -1);
}

Pair EvalTerm(int pos) {
  Pair p = EvalElem(pos);
  assert(p.second != -1);

  pos = p.second;
  if (buf[pos] == '*') {
    Pair q = EvalExp(pos+1);
    return Pair(p.first * q.first, q.second);
  }

  if (buf[pos] == '/') {
    Pair q = EvalExp(pos+1);
    return Pair(p.first/q.first, q.second);
  }

  return p;
}

Pair EvalExp(int pos) {
  if (buf[pos] == '(') {
    Pair p = EvalExp(pos+1);
    return Pair(p.first, p.second+1);
  }

  Pair p = EvalTerm(pos);
  pos = p.second;
  int res = p.first;
  while (1) {

    if (buf[pos] == '=' || buf[pos] == ')') {
      return Pair(res, pos);
    }

    Pair q = EvalTerm(pos+1);
    if (buf[pos] == '+') res += q.first;
    else if (buf[pos] == '-') res -= q.first;
    else assert(0);

    pos = q.second;
  }

}

int main() {
  scanf("%d", &_);
  while (_--) {
    scanf("%s", buf);
    n = strlen(buf);

    Pair res = EvalExp(0);
    assert(res.second == n-1);
    printf("%d\n", res.first);
  }
}