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>
using namespace std;
// const string S = "(1+1)*2";
string S;
int cur = 0;
int digit();
int number();
int factor();
int term();
int _term(int m);
int exp();
int _exp(int m);
int parse();
bool isdigit(char);
bool is_plu_min(char);
bool is_tim_div(char);
int main() {
  int N;
  cin >> N;
  for (int i=0;i<N;i++) {
    cin >> S;
    cur = 0;
    S.resize(S.size()-1);
    cout << parse() << endl;
  }
  return 0;
}
int digit() {
  int n = S[cur] - '0';
  cur++;
  return n;
}
int number() {
  int n = digit();
  while (cur < S.size() && isdigit(S[cur]))
    n = n*10 + digit();
  return n;
}
bool isdigit(char c) {
  if (c <= '9' and c >= '0') return true;
  else return false;
}
bool is_plu_min(char c) {
  if (c == '+' || c == '-') return true;
  else return false;
}
bool is_tim_div(char c) {
  if (c == '*' || c == '/') return true;
  else return false;
}
// exp    = term exp`
// exp`   = + term exp` | eps
// term   = factor term`
// term`  = * factor term` | eps
// factor = ( exp ) | num
int term() {
  int n = factor();
  return _term(n);
}
int _term(int m) {
  int n = m;
  switch (S[cur]) {
    case '*':
      cur++;
      n *= factor();
      return _term(n);
    case '/':
      cur++;
      n /= factor();
      return _term(n);
    default:
      return n;
  }
}
int factor() {
  if (S[cur] != '(') return number();
  else {
    cur++;
    int n = exp();
    cur++;
    return n;
  }
}
int exp() {
  int n = term();
  return _exp(n);
}
int _exp(int m) {
  int n = m;
  switch (S[cur]) {
    case '+':
      cur++;
      n += term();
      return _exp(n);
    case '-':
      cur++;
      n -= term();
      return _exp(n);
    default:
      return n;
  }
}
int parse() {
  return exp();
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <utility>
using namespace std;

typedef pair<int, int> Pair;

int _;
int n;
char buf[11451419];

Pair EvalElem(int pos);
Pair EvalTerm(int pos);
Pair EvalExp(int pos);

Pair EvalElem(int pos) {
  if (buf[pos] == '(') {
    Pair p = EvalExp(pos+1);
    return Pair(p.first, p.second+1);
  }

  char c = buf[pos];
  if ('0' <= c && c <= '9' || c == '-') {
    char *next;
    int res = strtol(buf+pos, &next, 10);
    return Pair(res, next-buf);
  }

  return Pair(-1, -1);
}

Pair EvalTerm(int pos) {
  Pair p = EvalElem(pos);
  assert(p.second != -1);

  pos = p.second;
  int res = p.first;
  while (1) {
    char c = buf[pos];
    if (c != '*' && c != '/') break;

    if (c == '*') {
      Pair q = EvalElem(pos+1);
      res *= q.first;
      pos = q.second;
    } else {
      Pair q = EvalElem(pos+1);
      res /= q.first;
      pos = q.second;
    }
  } 

  return Pair(res, pos);
}

Pair EvalExp(int pos) {
  Pair p = EvalTerm(pos);
  pos = p.second;

  char c = buf[pos];
  int res = p.first;
  if (c == '=' || c == ')') {
    return Pair(res, pos);
  }

  Pair q = EvalExp(pos+1);
  if (c == '+') res += q.first;
  else if (c == '-') res -= q.first;
  else assert(0);

  return Pair(res, q.second);
}

int main() {
  scanf("%d ", &_);
  while (_--) {
    scanf("%s", buf);
    n = strlen(buf);

    Pair res = EvalExp(0);
    assert(res.second == n-1);
    printf("%d\n", res.first);
  }
}

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

using namespace std;

typedef string::const_iterator Iter;

int express(Iter &p);
int term(Iter &p);
int factor(Iter &p);
int number(Iter &p);

int express(Iter &p) {
	int r = term(p);
	for(;;) {
		if(*p == '+') {
			p++;
			int rs = term(p);
			r += rs;
		}
		else if(*p == '-') {
			p++;
			int rs = term(p);
			r -= rs;
		}
		else
			break;
	}
	return r;
}


int term(Iter &p) {
	int r = factor(p);
	for(;;) {
		if(*p == '*') {
			p++;
			int rs = factor(p);
			r *= rs;
		}
		else if(*p == '/') {
			p++;
			int rs = factor(p);
			r /= rs;
		}
		else
			break;
	}
	return r;
}

int factor(Iter &p) {
	if(*p == '(') {
		p++;
		int r = express(p);
		p++; // skip )
		return r;
	}
	else
		return number(p);
}

int number(Iter &p) {
	int r = 0;
	while(isdigit(*p)) {
		r *= 10;
		r += (*p) - '0';
		p++;
	}
	return r;
}

int main() {
	int N; cin >> N;
	cin.ignore();
	while(N--) {
		string line;
		getline(cin, line);
		Iter begin = line.begin();
		int ans = express(begin);
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<string>
#include<ctype.h>
 
std::string s;
std::string::iterator it;
 
int term();
int fact();
 
// ?¨????
int expr()
{
    int p = term();
     
    // + or -
    while( *it == '+' || *it == '-' ){
        if( *it == '+' ){
            it++;
            int q = term();
            p += q;
        }
        else{
            it++;
            int q = term();
            p -= q;
        }
    }
     
    return p;
}
 
// ???????¨????
int term()
{
    int p = fact();
     
    while( *it == '*' || *it == '/' ){
        if( *it == '*' ){
            it++;
            int q = fact();
            p *= q;
        }
        else{
            it++;
            int q = fact();
            p /= q;
        }
    }
     
    return p;
}
 
// ??¬??§??? or ??°???
int fact()
{
    if( *it == '(' ){
        it++;
        int p = expr();
        it++;
         
        return p;
    }
    else{
        int p = 0;
         
        while( isdigit( *it ) ){
            p *= 10;
            p += *it - '0';
            it++;
        }
         
        return p;
    }
}
 
int main()
{
    int n;
    std::cin >> n;
     
    while( n-- ){
        std::cin >> s;
        s[s.size()-1] = '\0';
        it = s.begin();
        std::cout << expr() << std::endl;
    }
 
    return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

typedef long long ll;

string S;
size_t cur=0;
int parse();

int digit(){
    assert(isdigit(S[cur]));
    int n=S[cur]-'0';
    cur++;
    return n;
}

int number(){
    int n=digit();
    while(cur<S.size()&&isdigit(S[cur]))
	n=n*10+digit();
    return n;
}

int expression();
int factor(){
	if(S[cur]!='(')return number();
	cur++;
	int n=expression();
	assert(S[cur]==')');
	cur++;
	return n;
}

int term(){
    int a=factor();
    while(cur<S.size()&&(S[cur]=='*'||S[cur]=='/')){
		char op=S[cur++];
		int b=factor();
		if(op=='*')a*=b; else a/=b;
    }
    return a;
}

int expression(){
    int a=term();
    while(cur<S.size()&&(S[cur]=='+'||S[cur]=='-')){
	char op=S[cur++];
	int b=term();
	if(op=='+')a+=b; else a-=b;
    }
    return a;
}

int main() {
    int n;
    cin>>n;
    while(cin>>S){
	cur=0;
	cout<<expression()<<endl;
    }
}