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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)
typedef string::const_iterator State;

string s;

int eval(State &beg);

int number( State &beg ){
    string ret="";
    while( *beg!='=' && isdigit(*beg) ){
        ret+=string(1,*beg);
        beg++;
    }
    
    return stoi(ret);
}

int term(State &beg){
    int ret = 0;
    if( *beg=='(' ){
        beg++;
        ret = eval(beg);
        beg++;
    }
    else{
        ret = number(beg);
    }
    while( *beg!='=' && *beg!=')' && *beg!='+' && *beg!='-' ){
        beg++;
        if( *(beg-1)=='*' )         ret*=term(beg);
        else if( *(beg-1)=='/' )    ret/=term(beg);
        else throw(string(1,*(beg-1)));
    }
    return ret;
}

int eval(State &beg){
    int ret=term(beg);
    
    while(*beg!='=' && *beg!=')'){
        beg++;
        if(*(beg-1)=='+')       ret+=term(beg);
        else if(*(beg-1)=='-')  ret-=term(beg);
        else throw("error");
    }
    return ret;
}
int main(){
    int n;
    cin>>n;
    rep(i,n){
        cin>>s;
        
        State beg = s.begin();
        try{
            cout<<eval(beg)<<endl;
        }catch(string s){
            cout<<s<<endl;
        }
    }
}

C++: #include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <stdexcept>
using namespace std;
string input;

inline bool is_all_digit(string &in)
{
    for (auto i : in)
    {
        if (!isdigit(i))
            return false;
    }
    return true;
}
vector<string> split(string in)
{
    vector<string> spl;
    int pos = 0;
    if (in[pos] == '-')
    {
        pos++;
        while (pos < in.size())
        {
            if (isdigit(in[pos]))
            {
                pos++;
            }
            else
            {
                break;
            }
        }
        spl.push_back(in.substr(0, pos));
        in.erase(0, pos);
        pos = 0;
    }
    while (pos < in.size())
    {
        if (!isdigit(in[pos]))
        {
            if (pos != 0)
            {
                spl.push_back(in.substr(0, pos));
                in.erase(0, pos);
                pos = 0;
            }
            else
            {
                if (in[0] == '(')
                {
                    int cnt = 1;
                    int r_pos = 1;
                    for (r_pos = 1; r_pos < in.size(); r_pos++)
                    {
                        if (in[r_pos] == '(')
                            cnt++;
                        if (in[r_pos] == ')')
                            cnt--;
                        if (cnt == 0)
                            break;
                    }
                    spl.push_back(in.substr(pos + 1, r_pos - 0 - 1));
                    in.erase(0, r_pos + 1);
                    pos = 0;
                    continue;
                }
                else if (in[0] == '+' || in[0] == '-' || in[0] == '*' || in[0] == '/')
                {
                    spl.push_back(in.substr(0, 1));
                    in.erase(0, 1);
                    pos = 0;
                }
            }
        }
        else
        {
            pos++;
        }
    }
    if (in.size() != 0)
        spl.push_back(in);
    return spl;
}
int cal(string &in_str)
{
    auto in = split(in_str);
    while (in.size() == 1 && !is_all_digit(in[0]))
    {
        in = split(in[0]);
    }
    while (in.size() != 1)
    {
        auto pos = in.begin();
        while (pos != in.end())
        {
            if (*pos == "*")
            {
                pos--;
                *pos = to_string(cal(*pos) * cal(*(pos + 2)));
                in.erase(pos + 1, pos + 3);
            }
            else if (*pos == "/")
            {
                pos--;
                *pos = to_string(cal(*pos) / cal(*(pos + 2)));
                in.erase(pos + 1, pos + 3);
            }
            if (in.size() == 1)
                break;
            if (pos != in.end())
                pos++;
        }
        pos = in.begin();
        while (pos != in.end())
        {
            if (*pos == "+")
            {
                pos--;
                *pos = to_string(cal(*pos) + cal(*(pos + 2)));
                in.erase(pos + 1, pos + 3);
            }
            else if (*pos == "-")
            {
                pos--;
                *pos = to_string(cal(*pos) - cal(*(pos + 2)));
                in.erase(pos + 1, pos + 3);
            }
            if (in.size() == 1)
                break;
            if (pos != in.end())
                pos++;
        }
    }
    try
    {
        return (stoi(in[0]));
    }
    catch (const std::invalid_argument &a)
    {
        cerr << a.what() << input << endl;
    }
}
int main()
{

    int n;
    cin >> n;
    while (n--)
    {
        cin >> input;
        input.erase(input.end() - 1);
        cout << cal(input) << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
typedef vector<vector<int> > VVI;
const int INF = 1e9;

string S;

int expr(int &pos);

// 数
int number(int &pos)
{
	int res=0;
	while (isdigit(S[pos])) {
		res *= 10;
		res += S[pos]-'0';
		pos++;
	}
	return res;
}

// ()か数
int factor(int &pos)
{
	int res=0;
	
	if (S[pos] == '(') {
		pos++; // skip '('
		res = expr(pos);
		pos++; // skip ')'
	} else {
		res = number(pos);
	}
	
	return res;
}

// 乗算
int term(int &pos)
{
	int res = factor(pos);
	while (1) {
		if (S[pos] == '*') {
			pos++; // skip '*'
			res *= factor(pos);
		} else if (S[pos] == '/') {
			pos++; // skip '/'
			res /= factor(pos);
		} else {
			break;
		}
	}
	return res;
}

// 四則演算
int expr(int &pos)
{
	int res = term(pos);
	
	while (1) {
		if (S[pos] == '+') {
			pos++; // skip '+'
			res += term(pos);
		} else if (S[pos] == '-') {
			pos++; // skip'-'
			res -= term(pos);
		} else {
			break;
		}
	}
	return res;
}

int main()
{
	int N;
	cin>>N;
	cin.ignore();
	rep(i, N) {
		getline(cin, S);
		int pos = 0;
		cout << expr(pos) << endl;
	}
}