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 <cstdlib>
#include <sstream>
using namespace std;

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

bool is_digit(char c){
  return '0' <= c && c <= '9';
}
string i2s(int i) {
  stringstream ss;
  ss << i;
  return ss.str();
}

string parse(int i, string s) {
  //cout<<s<<endl;
  bool flag = true;
  
  // brace
  if (s.find('(') != -1) {
    // æª©ç`FbNµÄA')'Éoï¤êÆ
    // »¤ÅÈ¢êÉª¯é
    bool mode = true;
    REP(j,s.find('(')+1, s.size()) {
      if (s[j] == ')') break;
      if (s[j] == '(') {
        mode = false;
        break;
      }
    }
    // ÊÌÊuðæ¾·é
    int lbr = s.find('('), rbr;
    if (mode) {
      rbr = s.find(')');
    } else {
      for(int j=s.size()-1;j>=0;j--) if (s[j] == ')') {
        rbr = j; break;
      }
    }
    // ÊàÌvZðæÉs¤½ßÉssð¾é
    string inner = parse(0, s.substr(lbr+1, rbr-lbr-1));
    // ÊàðÁ·é
    s.erase(lbr, rbr-lbr+1);
    s.insert(lbr, inner);
    //cout<<"brace:"<<s<<endl;
    return parse(0, s);
  }
  
  rep(i,s.size()) if (s[i] == '*' || s[i] == '/') {
    int lhs, rhs, res;
    int li = i-1, ri = i+1;
    if (ri + 1 < s.size() && s[ri] == '-') ri++;

    while (is_digit(s[li]) && li >= 0) {
      if (s[li] == '-') break;
      li--;
    }
    while (is_digit(s[ri]) && ri < s.size()) ri++;
    lhs = atoi(s.substr(li+1, i-1-li).c_str());
    rhs = atoi(s.substr(i+1, ri-1-i).c_str());
    //cout<<s.substr(li+1, i-1-li)<<"|"<<s.substr(i+1, ri-1-i)<<endl;

    if (lhs == 0 || rhs == 0) {
      res = 0;
    } else {
      if (s[i] == '*') {
        res = lhs * rhs;
      } else {
        res = lhs / rhs;
      }
    }
    
    s.erase(li+1, ri-li-1);
    s.insert(li+1, i2s(res));
    //cout<<"tmp:"<<s<<endl;
    return parse(0, s);
  }
  
  rep(i,s.size()) if (s[i] == '+' || s[i] == '-') {
    if (s[i] == '-' && i == 0) continue; 
    int lhs, rhs, res;
    int li = i-1, ri = i+1;
    if (ri + 1 < s.size() && s[ri] == '-') ri++;
    
    while (is_digit(s[li]) || s[li] == '-' && li >= 0) li--;
    while (is_digit(s[ri]) && ri < s.size()) ri++;
    lhs = atoi(s.substr(li+1, i-1-li).c_str());
    rhs = atoi(s.substr(i+1, ri-1-i).c_str());
    //cout<<s.substr(li+1, i-1-li)<<"|"<<s.substr(i+1, ri-1-i)<<endl;
    if (s[i] == '+') {
      res = lhs + rhs;
    } else {
      res = lhs - rhs;
    }
    s.erase(li+1, ri-li-1);
    s.insert(li+1, i2s(res));
    //cout<<"tmp:"<<s<<endl;
    return parse(0, s);
  }
  
  return s;
}

void solve() {
  string s; cin>>s;
  s = s.substr(0, s.size()-1);
  cout<<parse(0, s)<<endl;
  //cout<<"+++++"<<endl;
}

int main (int argc, char const* argv[]) {
  int n; cin>>n;
  rep(i,n) solve();
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;

int expression(State &begin);

int term(State &begin);

int factor(State &begin);

int number(State &begin);

void consume(State &begin,char expected);

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

    State begin = s.begin();
    int ans=expression(begin);
    consume(begin,'=');
    cout<<ans<<endl;
  }

}


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

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


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


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

  for(;;){
    if(*begin =='*'){
      consume(begin,'*');
      ret *= factor(begin);
    }
    else if(*begin =='/'){
      consume(begin,'/');
      ret /= factor(begin);
    }
    else break;
  }

  return ret;
}


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

  for(;;){
    if(*begin =='+'){
      consume(begin,'+');
      ret += term(begin);
    }
    else if(*begin =='-'){
      consume(begin,'-');
      ret -= term(begin);
    }
    else break;
  }
  return ret;
}



void consume(State &begin, char expected) {
  if (*begin == expected) {
    begin++;
  } else {
    cerr << "Expected '" << expected << "' but got '" << *begin << "'"
      << endl;
    cerr << "Rest string is '";
    while (*begin) {
      cerr << *begin++;
    }
    cerr << "'" << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
string s;
int a;
int func();//+-
int num();
int func2();//*/
int func3();//()
int num(){
    int out=0;
    while(isdigit(s[a])){
        out*=10;out+=s[a]-'0';
        a++;
    }
    return out;
}
int func3(){
    int out;
    if(s[a]=='('){
        a++;
        out=func();
        a++;
    }else out=num();
    return out;
}
int func2(){
    int out=func3();
    while(1){
        if(s[a]=='*'){
            a++;
            out*=func3();
        }else if(s[a]=='/'){
            a++;
            out/=func3();
        }else break;
    }
    return out;
}   
int func(){
    int out=func2();
    while(1){
        if(s[a]=='+'){
            a++;out+=func2();
        }else if(s[a]=='-'){
            a++;out-=func2();
        }else break;
    }
    return out;
}
int main(){
	int q;
	cin>>q;
	while(q--){
		cin>>s;
		a=0;
		cout<<func()<<endl;
	}
}

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

using namespace std;
int cur = 0;
string S;
int expression();
int term();
int main() {
  int times;
  cin >>times;
  for(int i = 0 ; i < times; i++){
      cin >> S;
      cur = 0;
      S.resize(S.size()-1);
      cout << expression() <<endl;
  }

}
int digit() {
  assert(isdigit(S[cur]));
  int n = S[cur] -'0';
  cur = cur+1;
  return n;
}
int number() {
  int n = digit();
  while(cur <S.size() && isdigit(S[cur])){
      n = n*10 + digit();
  }
  return n;
}
int expression() {
  int sum = term();
  while (S[cur] == '+' || S[cur] == '-'){
    char op = S[cur];
    cur +=1;
    int b = term();
    if(op ==  '+') sum +=b;
    else sum -= b;
  }
  return sum;
}
int term() {
  int a = number();
  while(cur < S.size()
        && (S[cur] == '*' || S[cur] == '/')){
          char op = S[cur];
          cur +=1;
          int b = number();
          if(op == '*') a *=b;
          else a/=b;
        }
  return a;
}