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>

using namespace std;

typedef string::const_iterator State;

/*
  <num> ::= '1'|'2'|...|'0'
  <term> ::= <num or kakko> ('*' or '/' ) <num or kakko>
  <exp> ::= <term> ('+' or '-' ) <term>
  <kakko> ::= '(' <exp> ')'
  <factor> ::= <num> or <kakko>
*/

int number(State&);
int kakko(State&);
int factor(State&);
int term(State&);
int expression(State&);

int main(){
  string input;
  int n,ret;
  cin >> n;
  cin.ignore();
  for(int i = 0;i < n;i++){
    getline(cin, input);
    State begin = input.begin();
    ret = expression(begin);
    cout << ret << endl;
  }
  return 0;
}


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

int factor(State &begin){
  int ret = 0;
  if(*begin == '('){
    begin++;
    ret += expression(begin);
    begin++;
  }else{
    return number(begin);
  }
  return ret;
}

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

C++: #include<iostream>
#define INF (1<<26)
using namespace std;
int n;



int compute(int a,int b,string str){
  int i=a,sum=0,tmp=INF,tmp2=INF,cnt=0;
  while(1){
    sum=0;
    if(str[i]=='('){
      sum=compute(i+1,0,str);
      for(i=a+1;i<(int)str.size();i++){
	if(str[i]==')')cnt--;
	if(str[i]=='(')cnt++;
	if(cnt<0)break;
      }
      i++;
    }else{
      while(1){
	if('0'<=str[i]&&str[i]<='9'){
	  sum*=10;
	  sum+=(str[i]-'0');
	  i++;
	}else{
	  break;
	}
      }
    }
    
    if(b==1){
      sum*=-1;
      b=0;
    }
    if(tmp!=INF){
      sum*=tmp;
      tmp=INF;
    }
    if(tmp2!=INF){
      sum=tmp2/sum;
      tmp2=INF;
    }
    
    if(str[i]=='\0'||str[i]==')'||str[i]=='=')return sum;
    if(str[i]=='+')return sum + compute(i+1,0,str);
    if(str[i]=='-')return sum + compute(i+1,1,str);
    if(str[i]=='*'){
      i++;
      tmp=sum;
    }else if(str[i]=='/'){
      i++;
      tmp2=sum;
    }
  }
      
}


int main(){
  string str;
  cin>>n;
  while(n--){
    cin>>str;

    //cout<<str<<endl;
    cout<<compute(0,0,str)<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<cctype>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef string::const_iterator State;

int ctoi(const char &c)
{
	return c - '0';
}

int expression(State &);
int term(State &);
int factor(State &);
int number(State &);

int expression(State &itr)
{
	int ret=term(itr);

	while (true)
	{
		if (*itr == '+')
		{
			itr++;
			ret = ret + term(itr);
		}
		else if (*itr == '-')
		{
			itr++;
			ret = ret - term(itr);
		}
		else
		{
			break;
		}
	}

	return ret;
}

int term(State &itr)
{
	int ret=number(itr);

	while (true)
	{
		if (*itr == '*')
		{
			itr++;
			ret = ret*factor(itr);
		}
		else if (*itr == '/')
		{
			itr++;
			ret = ret / factor(itr);
		}
		else
		{
			break;
		}
	}

	return ret;
}

int factor(State &itr)
{
	int ret;

	if (*itr == '(')
	{
		itr++;
		ret = expression(itr);
		itr++;
	}
	else
	{
		ret = number(itr);
	}

	return ret;
}

int number(State &itr)
{
	int ret = 0;

	while (isdigit(*itr))
	{
		ret *= 10;
		ret += ctoi(*itr);
		itr++;
	}

	return ret;
}

int main()
{
	int n;
	cin >> n;
	cin.ignore();
	REP(i, n)
	{
		string str;
		getline(cin, str);
		State begin = str.begin();
		int ans = expression(begin);
		cout << ans << endl;
	}
	return 0;
}

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

class calc{
  string s;
  string::iterator it;

public:
  calc(const string&str){
    s = str;
    it = s.begin();
  }

  int fact(){
    if(*it == '('){
      ++it;
      int ret = exp();
      ++it;
      return ret;
    }
    else{
      int ret = 0;
      while('0' <= *it && *it <= '9'){
	ret *= 10;
	ret += *it - '0';
	++it;
      }
      return ret;
    }
  }

  int term(){
    int ret = fact();
    while(*it == '*' || *it == '/'){
      if(*it == '*'){
	++it;
	ret *= fact();
      }
      else if(*it == '/'){
	++it;
	ret /= fact();
      }
    }
    return ret;
  }
  
  int exp(){
    int ret = term();

    while(*it == '+' || *it == '-'){
      if(*it == '+'){
	++it;
	ret += term();
      }
      else if(*it == '-'){
	++it;
	ret -= term();
      }
    }
    return ret;
  }
};

int main(){
  string str;
  int n;

  cin >> n;
  while(n--){
    cin >> str;
    calc ans(str);
    cout << ans.exp() << endl;
  }

  return 0;
}

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

using namespace std;

/*
 exp    ::= term    | exp  + term   | exp  - term
 term   ::= factor  | term * factor | term / factor
 factor ::= literal | (exp) | -factor
*/

int perseExp( string str );
int perseTerm( string str );
int perseFactor( string str );

int perseExp( string str ){
  //cout << "perseExp" << str << endl;
  int  nest = 0;
  char op   = 0;
  int pos;
  for(int i=str.size()-1; i>0; i--){
    char c = str[i];
    if(nest == 0 && (c == '+' || c == '-')){
      op = c;
      pos = i;
      break;
    }
    if(c == '('){
      nest--;
    }else if(c == ')'){
      nest++;
    }
    if(nest < 0)
      throw "Error: perseExp";
  }
  if(op == 0){
    return perseTerm(str);
  }else{
    int op1 = perseExp( str.substr(0, pos) );
    int op2 = perseTerm( str.substr(pos+1) );
    if(op == '+'){
      return op1 + op2;
    }else{
      return op1 - op2;
    }
  }
}

int perseTerm( string str ){
  //cout << "perseTerm" << str << endl;
  int nest = 0;
  char op = 0;
  int pos;
  for(int i=str.size()-1; i>0; i--){
    char c = str[i];
    if(nest == 0 && (c == '*' || c == '/')){
      op = c;
      pos = i;
      break;
    }
    if(c == '('){
      nest--;
    }else if(c == ')'){
      nest++;
    }
    if(nest < 0)
      throw "Error: perseTerm";
  }
  if(op == 0){
    return perseFactor(str);
  }else{
    int op1 = perseTerm( str.substr(0, pos) );
    int op2 = perseFactor( str.substr(pos+1) );
    if(op == '*'){
      return op1 * op2;
    }else{
      return op1 / op2;
    }
  }
}

int perseFactor( string str ){
  //cout << "perseFactor" << str << endl;
  if(str.size() == 0)
    throw "Parse Error: perseFactor";

  char firstStr = str[0];
  if(firstStr == '('){
    return perseExp( str.substr(1, str.size()-2) );
  }else if(firstStr == '-'){
    return -1 * perseFactor( str.substr(1) );
  }else{
    bool f = true;
    for(int i=0; i<str.size(); i++){
      if(!isdigit(str[i])) f = false;
    }
    if(f){
      int num; sscanf(str.c_str(), "%d", &num);
      return num;
    }else{
      return perseExp(str);
    }
  }
}

string trim(string str){
  while(str.find(' ') != -1) str.erase(str.find(' '), 1);
  while(str.find('=') != -1) str.erase(str.find('='), 1);
  return str;
}

int main(){
  int n;
  string str;
  getline(cin,str);
  sscanf(str.c_str(),"%d",&n);
  while(n-->0){
    getline(cin,str);
    str = trim(str);
    int ret = perseExp(str);
    cout << ret << endl;
  }
  return 0;
}