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 <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;
	cerr<<n;
	while (n--) {
		cin >> input;
		//input.erase(input.end() - 1);
		//cout << cal(input) << endl;
		cerr << input << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(5)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<short, short> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int calc(string s)
{
	vi v;
	REP(i, s.size())
	{
		if (s[i] == '+') v.push_back(0);
		else if (s[i] == '-') v.push_back(1);
		else if (s[i] == '*') v.push_back(2);
		else if (s[i] == '/') v.push_back(3);
		else
		{
			int tmp = s[i] - '0';
			int t = i+1;
			while (isdigit(s[t]))
			{
				tmp = tmp * 10 + s[t] - '0';
				t++;
			}
			i = t - 1;
			v.push_back(tmp);
		}
	}

	while (v.size() > 1)
	{
		for (int i = 1; i < v.size();i+=2)
		{
			if (v[i]==2)
			{
				int tmp = v[i - 1] * v[i + 1];
				v[i - 1] = tmp;
				v.erase(v.begin() + i + 1);
				v.erase(v.begin() + i);
				continue;
			}
			else if (v[i] == 3)
			{
				int tmp = v[i - 1] / v[i + 1];
				v[i - 1] = tmp;
				v.erase(v.begin() + i + 1);
				v.erase(v.begin() + i);
				continue;
			}
		}
		for (int i = 1; i < v.size(); i += 2)
		{
			if (v[i] == 0)
			{
				int tmp = v[i - 1] + v[i + 1];
				v[i - 1] = tmp;
				v.erase(v.begin() + i + 1);
				v.erase(v.begin() + i);
				break;
			}
			else if (v[i] == 1)
			{
				int tmp = v[i - 1] - v[i + 1];
				v[i - 1] = tmp;
				v.erase(v.begin() + i + 1);
				v.erase(v.begin() + i);
				break;
			}
		next:;
		}
	}
	return v[0];
}

int solve(string s)
{
	while (1)
	{
		if (find(ALL(s), '(') == s.end())
		{
			return calc(s);
		}
		else
		{
			string tmp;
			REP(i, s.size())
			{
				if (s[i] != '(') tmp.push_back(s[i]);
				else
				{
					int j;
					for (j = s.size()-1;; j--)
					{
						if (s[j] == ')')
						{
							int t = solve(s.substr(i+1, j - i - 1));
							tmp += to_string(t);
							break;
						}
					}
					i = j;
				}
			}
			return solve(tmp);
		}
	}
	return 0;
}

int main()
{
	int sets;
	string s;
	cin >> sets;
	REP(set, sets)
	{
		cin >> s;
		s.erase(s.size() - 1);
		cout << solve(s) << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

string s;

int parse(int l, int r)
{
	int k = 0;
	for(int i = r - 1; i >= l; i--){
		if(s[i] == ')') k++;
		if(s[i] == '(') k--;
	
		if(!k && s[i] == '+') return parse(l, i) + parse(l+i, r);
		if(!k && s[i] == '-') return parse(l, i) - parse(l+i, r);
	}
	
	for(int i = r - 1; i >= l; i--){
		if(s[i] == ')') k++;
		if(s[i] == '(') k--;
	
		if(!k && s[i] == '*') return parse(l, i) * parse(l+i, r);
		if(!k && s[i] == '/') return parse(l, i) / parse(l+i, r);
	}
	
	if(s[l] == '(' && s[r-1] == ')')return parse(l+1,r-1);
	
	return stoi(s.substr(l, r - l));
}

int main()
{
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s;
		cout << parse(0, s.size() - 1) << endl;
	}
}

C++: #include <iostream>

using namespace std;

class Parser{
    public:

    string s;
    int i, n;

    Parser(string s): s(s) {}

    int parse(){
        i = 0;
        n = s.length();
        return expr();
    }

    private:

    int expr(){
        int ret = term();
        while(s[i] != '='){
            if(s[i] == '+'){
                i++;
                ret += term();
            }else if(s[i] == '-'){
                i++;
                ret -= term();
            }else{
                break;
            }
        }
        return ret;
    }

    int term(){
        int ret = num();
        while(i < n){
            if(s[i] == '*'){
                i++;
                if(s[i] == '('){
                    i++;
                    ret *= expr();
                    i++;
                }else{
                    ret *= num();
                }
            }else if(s[i] == '/'){
                i++;
                if(s[i] == '('){
                    i++;
                    ret /= expr();
                    i++;
                }else{
                    ret /= num();
                }
            }else{
                break;
            }
        }
        return ret;
    }

    int num(){
        int ret = s[i] - '0';
        i++;
        return ret;
    }

};

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        Parser p = Parser(s);
        cout << p.parse() << endl;
    }
}