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 <algorithm>
#include <stack>
#include <vector>

using namespace std;

vector<string> toReversePorland(string str){

  vector<string> hand;
  vector<string> side;
  
  for(int i = 0; i < str.size(); i++){
    if(str[i] == ' ')
      continue;
    else if(str[i] == '=')
      break;
    if(str[i] >= '0' && str[i] <= '9'){
      string num;
      while(i < str.size()){
	if(str[i] < '0' || str[i] > '9'){
	  break;
	}
	num += str[i];
	i++;
      }
      hand.push_back(num);
      i--;
    }
    else if(str[i] == '('){
      string tmp;
      tmp += str[i];
      side.push_back(tmp);
    }
    else if(str[i] == ')'){
      // ツ右ツ環古環づ慊づ可可算ツ子ツづーツ暗ェツづつつクツづつ偲ィツ個ウツづ可姪淞つキ
      for(int j = side.size()-1 ; ;j--){
	if(side[j] == "("){
	  if(j != 0){
	    vector<string> tmp;
	    for(int k = 0; k < j; k++){
	      tmp.push_back(side[k]);
	    }
	    side = tmp;
	  }
	  else
	    side.clear();
	  break;
	}
	else{
	  string tmp = side[j];
	  hand.push_back(tmp);
	}
      }
    }
    else{
      if(side.size() == 0){
	string tmp;
	tmp += str[i];
	side.push_back(tmp);
      }
      else if(str[i] == '+' || str[i] == '-'){
	if(side[side.size()-1] == "*" || side[side.size()-1] == "/"){
	  hand.push_back(side[side.size()-1]);
	  string tmp;
	  tmp += str[i];
	  side[side.size()-1] = tmp;
	}
	else{
	  string tmp;
	  tmp += str[i];
	  side.push_back(tmp);
	}
      }
      else{
	if(side[side.size()-1] == "*" || side[side.size()-1] == "/"){
	  hand.push_back(side[side.size()-1]);
	  string tmp;
	  tmp += str[i];
	  side[side.size()-1] = string(tmp);
	}
	else{
	  string tmp;
	  tmp += str[i];
	  side.push_back(tmp);
	}
      }
    }
  }

  for(int i = side.size()-1; i >= 0; i--){
    hand.push_back(string(side[i]));
  }
  
  return hand;
}


int calc(vector<string> str){
  stack<int> st;
  for(int i = 0; i < str.size(); i++){
    if(str[i] == "+" || str[i] == "-" || str[i] == "*" || str[i] == "/"){
      int val[2];
      val[0] = st.top();
      st.pop();
      val[1] = st.top();
      st.pop();
      if(str[i] == "+"){
	st.push(val[0] + val[1]);
      }
      if(str[i] == "-"){
	st.push(val[1] - val[0]);
      }
      if(str[i] == "*"){
	st.push(val[0] * val[1]);
      }
      if(str[i] == "/"){
	st.push(val[1] / val[0]);
      }
    }
    else{
      st.push(atoi(str[i].c_str()));
    }
  }
  return st.top();
}

int main(){

  int n;
  string s;
  getline(cin,s);
  n = atoi(s.c_str());

  vector<string> input;
  string str;
  for(int i = 0; i < n; i++){
    getline(cin,str);
    input.push_back(str);
  }

  for(int i = 0; i < n; i++){
    str = input[i];
    // vector<string> vec = toReversePorland(str);
    // for(int i = 0; i < vec.size(); i++)
    //   cout << vec[i] << endl;
    cout << calc(toReversePorland(str)) << endl;
  }
  
  return 0;
}

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

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++;
        while(isdigit(s[i])){
            ret = ret * 10 + (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;
    }
}

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

using namespace std;

int p1( string const& expr, int& pos );
int p2( string const& expr, int& pos );
int p3( string const& expr, int& pos );

int p1( string const& expr, int& pos )
{
    int result = p2(expr, pos);
    if ( result == -1 )
        return -1;

    while( expr[pos] == '+' || expr[pos] == '-' ) {
        int const cp = pos;
        ++pos;
        int const a = p2( expr, pos );
        if ( expr[cp] == '+' )
            result += a;
        else
            result -= a;
    }

    return result;
}

int p2( string const& expr, int& pos )
{
    int result = p3(expr, pos);
    if ( result == -1 )
        return -1;

    while( expr[pos] == '*' || expr[pos] == '/' ) {
        int const cp = pos;
        ++pos;
        int const a = p3( expr, pos );
        if ( expr[cp] == '*' )
            result *= a;
        else
            result /= a;
    }

    return result;
}

int p3( string const& expr, int& pos )
{
    if ( expr[pos] >= '0' && expr[pos] <= '9' ) {
        string s;
        do {
            s += expr[pos];
            ++pos;
        } while( pos < expr.size() && expr[pos] >= '0' && expr[pos] <= '9' );
        
        return atoi( s.c_str() );

    } else if ( expr[pos] == '(' ){
        ++pos;
        int const res = p1( expr, pos );
        ++pos; // ')'
        return res;
    }

    return -1;
}



int main()
{
    int n;
    cin >> n;
    cin.ignore();
    for( int iii=0; iii<n; ++iii ) {
        string s;
        getline( cin, s );
//        cout << s << endl;
        int pos = 0;
        cout << p1( s, pos ) << endl;
    }
}