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;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int add();

string s;
int p;

int num()
{
	int res;
	if (s[p] == '(')
	{
		p++;
		res = add();
		assert(s[p] == ')');
		p++;
	}
	else if (isdigit(s[p]))
	{
		res = 0;
		while (p < s.size() && isdigit(s[p]))
		{
			res *= 10;
			res += s[p] - '0';
			p++;
		}
	}
	else assert(false);
	return res;
}

int mul()
{
	int res = num();
	while (p < s.size() && (s[p] == '*' || s[p] == '/'))
	{
		char c = s[p];
		p++;
		int r = num();
		if (c == '*')
		{
			res *= r;
		}
		else if (c == '/')
		{
			res /= r;
		}
	}
	return res;
}

int add()
{
	int res = mul();
	while (p < s.size() && (s[p] == '+' || s[p] == '-'))
	{
		char c = s[p];
		p++;
		int r = mul();
		if (c == '+')
		{
			res += r;
		}
		else if (c == '-')
		{
			res -= r;
		}
	}
	return res;
}

int solve()
{
	p = 0;
	return add();
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n; cin >> n;
	REP(cs, n)
	{
		cin >> s;
		s = s.substr(0, s.size() - 1);
		cout << solve() << endl;
	}
	return 0;
}

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

int calc1();
int calc2();
int calc3();

int p;
string eq;

int calc1() {
  int a = calc2();
  while (eq[p]=='+' || eq[p]=='-') {
    if (eq[p]=='+') {
      p++;
      a += calc2();
    } else if (eq[p]=='-') {
      p++;
      a -= calc2();
    }
  }
  return a;
}

int calc2() {
  int a = calc3();
  while (eq[p]=='*' || eq[p]=='/') {
    if (eq[p]=='*') {
      p++;
      a *= calc3();
    } else if (eq[p]=='/') {
      p++;
      a /= calc3();
    }
  }
  return a;
}

int calc3() {
  int a;
  if (eq[p]=='(') {
    p++;
    a = calc1();
    p++;
  } else {
    a = 0;
    while (eq[p]>='0'&&eq[p]<='9') {
      a *= 10;
      a += eq[p++] - '0';
    }
  }
  return a;
}

int main() {
  int n, r;

  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> eq;
    p = 0;
    r = calc1();
    cout << r << endl;
  }
}

C++: #include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

const int IINF = INT_MAX;

enum Symbol { EXPS,EXPE,TERMS,TERME,FACTOR };

int exp(string &s,int &cur){

  stack<Symbol> sstack;
  stack<int> vstack;
  stack<char> ostack;
  sstack.push(EXPS);
  ostack.push('@'); // dammy;
  while( !sstack.empty() ){
    Symbol syb = sstack.top();
    char opr;
    int v1,v2,value;
    switch(syb){
    case EXPS:
      sstack.pop();
      sstack.push(EXPE);
      sstack.push(TERMS);
      break;

    case EXPE:
      opr = ostack.top();
      if( opr == '+' || opr == '-' ) {
        ostack.pop();
        v1 = vstack.top(); vstack.pop();
        v2 = vstack.top(); vstack.pop();
        vstack.push(((opr=='+')?(v2+v1):(v2-v1)));
      }
      if( s[cur] == '+' || s[cur] == '-' ){
        sstack.push(TERMS);
        ostack.push(s[cur++]);
      } else {
        sstack.pop();
      }
      break;

    case TERMS:
      sstack.pop();
      sstack.push(TERME);
      sstack.push(FACTOR);
      break;

    case TERME:
      opr = ostack.top();
      if( opr == '*' || opr == '/' ){
        ostack.pop();
        v1 = vstack.top(); vstack.pop();
        v2 = vstack.top(); vstack.pop();
        vstack.push(((opr=='*')?(v2*v1):(v2/v1)));
      }

      if( s[cur] == '*' || s[cur] == '/' ){
        sstack.push(FACTOR);
        ostack.push(s[cur++]);
      } else {
        sstack.pop();
      }
      break;

    case FACTOR:
      if( s[cur] == '(' ){
        ++cur;
        sstack.push(EXPS);
        ostack.push('(');
      } else if( s[cur] == ')' ){
        ++cur;
        sstack.pop();
        ostack.pop();
      } else if( '0' <= s[cur] && s[cur] <= '9' ) {
        value = 0;
        while( '0' <= s[cur] && s[cur] <= '9' )( value *= 10 ) += s[cur++] - '0';
        vstack.push(value);
        sstack.pop();
      } else assert(false); // invalid form
      break;

    default:
      break;
    }

  }
  assert(vstack.size() == 1);
  return vstack.top();
}

int main(){
  int T;
  cin >> T;
  cin.ignore();
  while(T--){
    string s;
    int cur = 0;
    getline(cin,s);
    cout << exp(s,cur) << endl;
  }
  return 0;
}

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

typedef string::const_iterator State;
class ParseError{};

typedef unsigned long long ull;
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define all(a) (a).begin() ,(a).end()

const double eps = 1e-10;
const double inf = (int)1e8;
 
int expression(State &begin);
int term(State &begin);
int number(State &begin);
int factor(State &begin);

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

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

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 factor(State &begin){
    if(*begin == '('){
        begin++;
        int ret = expression(begin);
        begin++; 
        return ret;
    } else {
        return number(begin);
    }
}

int main(void){
    int n;
    string s;
    cin>>n;
    getline(cin,s);
    while(n--){
        getline(cin,s);
        State begin = s.begin();
        cout<<expression(begin)<<endl;
    }
    return 0;
}