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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

vector<string> split(string delim,string str){
	vector<string> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find_first_of(delim) != string::npos){
				//cout << str.substr(i,j) << endl;
				if(str.substr(i,j-1).size() > 0 ) res.push_back(str.substr(i,j-1));
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

string calc(vector<string> v){
	stack<string> stk;
	for(int i=0;i<v.size();i++){
		ll num1;
		ll num2;
		char buf[256];
		string res;
		if(v[i]=="-"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			sscanf(str1.c_str(),"%lld",&num1);
			sscanf(str2.c_str(),"%lld",&num2);

			sprintf(buf,"%lld",num2-num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="+"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			sscanf(str1.c_str(),"%lld",&num1);
			sscanf(str2.c_str(),"%lld",&num2);

			sprintf(buf,"%lld",num2+num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="*"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			sscanf(str1.c_str(),"%lld",&num1);
			sscanf(str2.c_str(),"%lld",&num2);

			sprintf(buf,"%lld",num2*num1);
			res = buf;
			
			stk.push(res);
		}
		else if(v[i]=="/"){
			string str1 = stk.top();
			stk.pop();
			string str2 = stk.top();
			stk.pop();

			sscanf(str1.c_str(),"%lld",&num1);
			sscanf(str2.c_str(),"%lld",&num2);

			sprintf(buf,"%lld",num2/num1);
			res = buf;
			
			stk.push(res);
		}
		else{
			stk.push(v[i]);
		}
	}
	return stk.top();
}

vector<string> rvs_polish(string str){
	stack<string> stk;
	vector<string> v;

	string tmp="";
	vector<string> res;
	if(str[0]=='-'){
		str='0'+str;
	}
	for(int i=0;i<str.size();i++){
		if(str[i]=='*'){
			v.push_back(tmp);
			v.push_back("*");
			tmp="";
		}

		else if(str[i]=='/'){
			v.push_back(tmp);
			v.push_back("/");
			tmp="";
		}

		else if(str[i]=='-' && (str[i-1]=='*' || str[i-1]=='/' || str[i-1]=='-')){
			tmp+='-';
		}

		else if(str[i]=='-' && (str[i-1]!='*' && str[i-1]!='/' && str[i-1]!='-')){
			v.push_back(tmp);
			v.push_back("-");			
			tmp="";
		}

		else if(str[i]=='+'){
			v.push_back(tmp);
			v.push_back("+");			
			tmp="";
		}
		else if(str[i]=='='){
			v.push_back(tmp);
			v.push_back("=");			
			tmp="";
		}

		else{
			tmp+=str.substr(i,1);
		}
	}

	v.push_back(tmp);

	for(int i=0;i<v.size();i++){
		if(v[i]=="*"){
			if(stk.empty()){
				stk.push("*");
			}
			else{
				string opr = stk.top();
				if(opr == "-" || opr == "+"){
					stk.push("*");
				}
				else{
					while(!stk.empty()){
						res.push_back(stk.top());
						stk.pop();
					}
					stk.push("*");
				}
			}
		}

		else if(v[i]=="/"){
			if(stk.empty()){
				stk.push("/");
			}
			else{
				string opr = stk.top();
				if(opr == "-" || opr == "+" || opr == "*"){
					stk.push("/");
				}
				else{
					while(!stk.empty()){
						res.push_back(stk.top());
						stk.pop();
					}
					stk.push("/");
				}
			}
		}

		else if(v[i]=="-"){
			if(stk.empty()){
				stk.push("-");
			}
			else{
				while(!stk.empty()){
					res.push_back(stk.top());
					stk.pop();
				}
				stk.push("-");
			}
		}
		else if(v[i]=="+"){
			if(stk.empty()){
				stk.push("+");
			}
			else{
				while(!stk.empty()){
					res.push_back(stk.top());
					stk.pop();
				}
				stk.push("+");
			}
		}
		else{
			res.push_back(v[i]);
		}
	}

	while(!stk.empty()){
		res.push_back(stk.top());
		stk.pop();
	}

	return res;
}

void dfs(string str){
	stack<P> stk;
	for(int i=0;i<str.size();i++){
		if(str[i]=='(') {stk.push(P('(',i));}
		else if(str[i]==')') {
			char sym = stk.top().first;
			if(sym != '(') continue;

			int pos = stk.top().second;
			stk.pop();

			if(str.substr(pos+1,(i-1)-(pos+1)+1).find('(') == string::npos
				&& str.substr(pos+1,(i-1)-(pos+1)+1).find(')') == string::npos){
					vector<string> pol = rvs_polish(str.substr(pos+1,(i-1)-(pos+1)+1));
					string num = calc(pol);
					str.replace(pos,i-pos+1,num);
					//cout << str << endl;
					while(!stk.empty()) stk.pop();
					i=-1;
					continue;
			}
		}
	}

	vector<string> ans = rvs_polish(str);

	cout << calc(ans) << endl;
}

int main(){
	string str;
	while(getline(cin,str)){
		int n;
		sscanf(str.c_str(),"%d",&n);
		for(int i=0;i<n;i++){
			getline(cin,str);
			dfs(str.substr(0,str.size()-1));
		}
	}
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
using namespace std;
typedef string::const_iterator State;
class ParseError {};

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

int expression(State &begin){
    int ret = term(begin);
    for(;;){
        if(*begin == '+'){
            begin++;
            ret += term(begin);
        }else if(*begin == '-'){
            begin++;
            ret -= term(begin);
        }else{
            break;
        }
    }
    return ret;
}

int term(State &begin){
    int ret = number(begin);
    for(;;){
        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(){
    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 <<endl;
    }
}

C++: #include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

int roc = 0;
string s;
int insu();
int kou();
int shiki();

int insu() {
	if(s[roc] >= '0' && s[roc] <= '9') {
		int j = roc;
		while(roc < s.size() && s[roc] >= '0' && s[roc] <= '9') ++roc;
		return stoi(s.substr(j, roc - j));
	} else {
		++roc;
		int res = shiki();
		++roc;
		return res;
	}
}

int kou() {
	int res = insu();
	while (s[roc] == '*' || s[roc] == '/') {
		if(s[roc] == '*') {
			++roc;
			res *= insu();
		}
		else {
			++roc;
			res /= insu();
		}
	}
	return res;
}

int shiki() {
	int res = kou();
	while (s[roc] == '+' || s[roc] == '-') {
		if(s[roc] == '+') {
			++roc;
			res += kou();
		}
		else {
			++roc;
			res -= kou();
		}
	}
	return res;
}

int main(void) {
	int n;
	cin>>n;
	REP(roop, n) {
		roc = 0;
		cin>>s;
		s.pop_back();
		cout<<shiki()<<endl;
	}
}