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 <cctype>
using namespace std;

typedef string::const_iterator State;

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

int number(State& begin){
    int res = 0;
    while( isdigit(*begin) ){
        res *= 10;
        res += *begin - '0';
        begin++;
    }
    return res;
}

int term(State& begin){
    int res = factor(begin);
    for(;;){
        if( *begin == '*' ){
            begin++;
            res *= factor(begin);
        }else if( *begin == '/' ){
            begin++;
            res /= factor(begin);
        }else{
            break;
        }
    }
    return res;
}

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

int factor(State& begin){
    if(*begin == '('){
        begin++;
        int res = expr(begin);
        begin++;
        return res;
    }else{
        return number(begin);
    }
}

int main(void){
    int N;
    cin >> N;
    cin.ignore();
    for(string s;N--;){
        getline(cin, s);
        State begin = s.begin();
        cout << expr(begin) << endl;
    }
    return 0;
}

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

using namespace std;

using si = string::const_iterator;
class ParseError {};

using ll = long long;
using ull = unsigned long long;

void cch(si &p, char exp) {
  if (*p != exp) {
    cerr << "expected '" << exp << "' but got '" << *p << "'" << endl;
    cerr << "rest: '";
    for (; *p; *p++) cerr << *p;
    cerr << "'" << endl;
    throw ParseError();
  }
  p++;
}

ll number(si &p) {
  ll ret = 0;
  for ( ; isdigit(*p); p++)
    ret = ret * 10 + (*p - '0');
  return ret;
}

ll expr(si &p);

ll factor(si &p) {
  if (*p == '(') {
    cch(p, '(');
    ll ret = expr(p);
    cch(p, ')');
    return ret;
  }
  return number(p);
}

ll term(si &p) {
  ll ret = factor(p);
  while (true) {
    if (*p == '*') {
        cch(p, '*');
        ret *= factor(p);
    } else if (*p == '/') {
        cch(p, '/');
        ret /= factor(p);
    } else break;
  }
  return ret;
}

ll expr(si &p) {
  ll ret = term(p);
  while (true) {
    if (*p == '+') {
        cch(p, '+');
        ret += term(p);
    } else if (*p == '-') {
        cch(p, '-');
        ret -= term(p);
    } else break;
  }
  return ret;
}

int main(void) {
  int n;
  cin >> n;
  cin.ignore();
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);

    si p = s.begin();
    ll ans = expr(p);
    cch(p, '=');
    cout << ans << endl;
  }
}

C++: #include <iostream>
#include <string>
using namespace std;

int atoi(string s);
int calc(string in);

int main() {
	int n; cin >> n;
	for (int lop = 0; lop<n; lop++) {
		string in; cin >> in;
		cout << calc(in.substr(0, in.size() - 1)) << endl;
	}
}

int calc(string in) {
	//cout<<in<<endl;
	bool f = true;
	for (int i = 1; i<in.size(); i++) {
		if (in[i]<'0' || '9'<in[i]) {
			f = false;
			break;
		}
	}
	if (f) {
		if (in[0] == '-')
			return -atoi(in.substr(1, in.size() - 1));
		if (in[0] == '+')
			return atoi(in.substr(1, in.size() - 1));
		return atoi(in);
	}
	for (int i = 0; i<in.size(); i++) {
		if (in[i] == '+' || in[i] == '-' || in[i] == '(' || in[i] == ')') {
			f = true;
			break;
		}
	}
	if (!f) {
		int num = 1, start = 0;
		// if op * , else /
		bool op = true;
		for (int i = 0; i<in.size(); i++) {
			if (in[i] == '*' || in[i] == '/') {
				if (op)
					num *= atoi(in.substr(start, i - start));
				else
					num /= atoi(in.substr(start, i - start));
				start = i + 1;
				if (in[i] == '*')
					op = true;
				else
					op = false;
			}
			if (i == in.size() - 1) {
				if (op)
					num *= atoi(in.substr(start, 1 + i - start));
				else
					num /= atoi(in.substr(start, 1 + i - start));
				break;
			}
		}
		return num;
	}
	for (int i = 0; i<in.size(); i++) {
		if (in[i] == '(' || in[i] == ')') {
			f = false;
			break;
		}
	}
	if (f) {
		int start = 0, num = 0;
		// if op + , else - 
		bool op = true;
		for (int i = 0; i<in.size(); i++) {
			if (in[i] == '+' || in[i] == '-') {
				if (op)
					num += calc(in.substr(start, i - start));
				else
					num -= calc(in.substr(start, i - start));
				start = i + 1;
				if (in[i] == '+')
					op = true;
				else
					op = false;
			}
			if (i == in.size() - 1) {
				if (op)
					num += calc(in.substr(start, 1 + i - start));
				else
					num -= calc(in.substr(start, 1 + i - start));
				break;
			}
		}
		return num;
	}
	int level = 1;
	//cout<<in<<endl;
	if (in[0] != '(' || in[in.size() - 1] != ')')
		f = true;
	if (!f) {
		for (int i = 1; i < in.size() - 1; i++) {
			if (in[i] == '(')
				level++;
			if (in[i] == ')')
				level--;
			if (level == 0) {
				f = true;
				break;
			}
		}
		if (!f)
			return calc(in.substr(1, in.size() - 2));
	}
	level = 0;
	for (int i = 0; i<in.size(); i++) {
		if (in[i] == '(') {
			level++;
			continue;
		}
		if (in[i] == ')') {
			level--;
			continue;
		}
		if (level == 0 && (in[i] == '+' || in[i] == '-'))
			f = false;
	}
	if (f) {
		//cout<<in<<endl;
		level = 0;
		int start = 0;
		int num = 1;
		bool op = true;
		for (int i = 0; i<in.size(); i++) {
			if (i == in.size() - 1) {
				if (op)
					num *= calc(in.substr(start, 1 + i - start));
				else
					num /= calc(in.substr(start, 1 + i - start));
			}
			if (in[i] == '(') {
				level++;
				continue;
			}
			if (in[i] == ')') {
				level--;
				continue;
			}
			if (level == 0 && (in[i] == '*' || in[i] == '/')) {
				if (op)
					num *= calc(in.substr(start, i - start));
				else
					num /= calc(in.substr(start, i - start));
				start = i + 1;
				if (in[i] == '*')
					op = true;
				else
					op = false;
			}
		}
		return num;
	}
	int start = 0, num = 0;
	level = 0;
	bool op = true;
	for (int i = 0; i<in.size(); i++) {
		if (i == in.size() - 1) {
			if (op)
				num += calc(in.substr(start, 1 + i - start));
			else
				num -= calc(in.substr(start, 1 + i - start));
		}
		if (in[i] == '(') {
			level++;
			continue;
		}
		if (in[i] == ')') {
			level--;
			continue;
		}
		if (level == 0 && (in[i] == '+' || in[i] == '-')) {
			if (op)
				num += calc(in.substr(start, i - start));
			else
				num -= calc(in.substr(start, i - start));
			start = i + 1;
			if (in[i] == '+')
				op = true;
			else
				op = false;
		}
	}
	return num;
}

int atoi(string s) {
	int n = 0;
	for (int i = 0; i<s.size(); i++) {
		n = n * 10 + s[i] - '0';
	}
	return n;
}