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

using namespace std;

int main(){
    int n;
    string q, a, sop;
    stack<int> numstack;
    stack<string> opstack;
    map<string, int> oprank;
	vector<string> exq;
    oprank["/"] = oprank["*"] = 2;
    oprank["+"] = oprank["-"] = 1;
	oprank["("] = 0;
    cin >> n;
    for(int i(0);i < n;++i){
        cin >> q;
		exq.clear();
        a = "";
        for(int j(0);j < q.length();++j){
            if(q[j] < '0' || '9' < q[j]){
                if(a.length() > 0) exq.push_back(a);
                a = "";
				sop = string(1, q[j]);
                if(opstack.empty()){
					opstack.push(sop);
					continue;
				}
				if(sop == ")"){
					while(opstack.top() != "("){
						exq.push_back(opstack.top());
						opstack.pop();
					}
					opstack.pop();
				}
				else if(sop == "(") opstack.push(sop);
				else if(sop == "="){
					while(!opstack.empty()){
						exq.push_back(opstack.top());
						opstack.pop();
					}
				}
				else if(oprank[sop] <= oprank[opstack.top()]){
					while(!opstack.empty() && oprank[sop] <= oprank[opstack.top()]){
						exq.push_back(opstack.top());
						opstack.pop();
					}
					opstack.push(sop);
				}
				else opstack.push(sop);
            }
            else a += q[j];
        }
		for(string s : exq){
			if(s[0] < '0' || '9' < s[0]){
				int x, y;
				y = numstack.top();
				numstack.pop();
				x = numstack.top();
				numstack.pop();
				if(s == "+"){
					numstack.push(x + y);
				}
				else if(s == "-"){
					numstack.push(x - y);
				}
				else if(s == "*"){
					numstack.push(x * y);
				}
				else if(s == "/"){
					numstack.push(x / y);
				}
			}
			else numstack.push(stoi(s));
		}
		cout << numstack.top() << endl;
		numstack.pop();
    }
    return 0;
}

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

using namespace std;

typedef string::const_iterator State;

int expr(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=number(begin);
	for(;;){
		if(*begin=='*'){
			begin++;
			ret*=factor(begin);
		}else if(*begin=='/'){
			begin++;
			ret/=factor(begin);
		}else break;
	}
	return ret;
}

int expr(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=expr(begin);
		begin++;
		return ret;
	}else{
		return number(begin);
	}
}

int main(){
	int N;
	cin>>N;
	cin.ignore();
	for(int i=0;i<N;i++){
		string str;
		getline(cin,str);
		State begin=str.begin();
		int ans=expr(begin);
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include <iostream>

#include <cassert>
#include <cctype>
using namespace std;
string S;
size_t cur = 0;
int term();
int factor();
int expression();
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 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 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 factor(){
	if (S[cur] != '(') return number();
	cur += 1;
	int n = expression();
	assert(S[cur] == ')');
	cur +=1;
	return n;
}
int main() {

	int N;
	cin >> N;
	for (int i=0; i<N;++i){
		cur = 0;
		cin >> S;
		S.resize(S.size()-1);
		cout << expression() << endl;
	}
	return 0;

}

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

map<char,int> order;
string S; size_t cur=0;
stack<int> num,rnum;
stack<char> op,rop;

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

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

void calc(){
	int b=num.top();num.pop();
	int a=num.top();num.pop();
	char o=op.top();op.pop();
	int c;
	switch(o){
		case '+' :
			c=a+b;
			break;
		case '-' :
			c=a-b;
			break;
		case '*' :
			c=a*b;
			break;
		case '/' :
			c=a/b;
			break;
		default :
			break;
	}
	num.push(c);
	return ;
}

void calc2(){
	int a=rnum.top();rnum.pop();
	int b=rnum.top();rnum.pop();
	char o=rop.top();rop.pop();
	int c;
	switch(o){
		case '+' :
			c=a+b;
			break;
		case '-' :
			c=a-b;
			break;
		case '*' :
			c=a*b;
			break;
		case '/' :
			c=a/b;
			break;
		default :
			break;
	}
	rnum.push(c);
	return ;
}

int exp(){
	cur =0;
	int smax=S.size();
	while(cur < smax-1){
		//cout << cur << endl;
		if(isdigit(S[cur])){
			int a=number();
			num.push(a);
		}else if(!op.empty()&&op.top()!='('&&op.top()!=')'&& order[S[cur]] >= order[op.top()]){ //計算順序については改善の余地あり (　は最小に
			calc();
			op.push(S[cur++]);
		}else if(S[cur] == ')' ){
			calc();
			rnum.push(num.top());num.pop();
 			while(!op.empty()&&op.top()!='('){
				rop.push(op.top());op.pop();
				rnum.push(num.top());num.pop();
			}
			while(!rop.empty())
				calc2();
			num.push(rnum.top());rnum.pop();
			//cout << num.top() << endl;
			op.pop();cur++;
		}else{//ひとまず終了　演算記号のチェックも入れる
			//	cout << "come" << endl;
			op.push(S[cur++]);
		}
	}
	if(!op.empty())
		calc();
	//cout << num.top() << endl;//
	//int tmp=num.top();num.pop();
	//cout << num.top() << endl;//
	//num.push(tmp);

	rnum.push(num.top());num.pop();
	while(!op.empty()&&op.top()!='('){
		rop.push(op.top());op.pop();
		rnum.push(num.top());num.pop();
	}
	while(!rop.empty())
		calc2();
	num.push(rnum.top());rnum.pop();
	//cout<< " check "  << op.empty() << endl;
	int ans=num.top();
	num.pop();
	return ans;
}

int main(void){
	order['+']=2;
	order['-']=2;
	order['*']=1;
	order['/']=1;
	//cout << order['('] << endl;
	int n;
	cin >> n;
	while(n--){
		cin >> S;
		cout << exp() << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cassert>
#define REP(i,l,n) for(int i=l;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define MAX 100
using namespace std;
int ans;
int n,pointer;
char input[MAX];
int evalE();
int evalT();
int evalF();
int main(){
  cin >> n;
  rep(i,n){
    pointer = 0;
    cin >> input;
    ans = evalE();
    cout << ans <<endl;
  }
  return 0;
}
int evalE(){
  int value = evalT();
  while(true){
    if(input[pointer] == '+'){
      pointer++;
      value += evalT();
    }else if(input[pointer] == '-'){
      pointer++;
      value -= evalT();
    }else{
      break;
    }
  }
  return value;
}
int evalT(){
  int value = evalF();
  while(true){
    if(input[pointer] == '*'){
      pointer++;
      value *= evalF();
    }else if(input[pointer] == '/'){
      pointer++;
      value /= evalF();
    }else{
      break;
    }
  }
  return value;
}
int evalF(){
  int value = 0;
  if(input[pointer] == '('){
    pointer++;
    value = evalE();
    assert(input[pointer] == ')');
    pointer++;
  }
  while(input[pointer]>='0'&&input[pointer]<='9'){
    value *= 10;
    value += (int)(input[pointer++] - '0');
  }
  return value;
}