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<vector>
using namespace std;

int lp=0;
int solve(string str){
    vector<int>op;
    vector<char>ope;
    //cout<<str.length()<<endl;
    cout<<"str: "<<str<<endl;
    int i=0;
    if(str[0]=='-'){
        i++;
        int g=0;
        while(str[i]>='0'&&str[i]<='9'){
            g=g*10+str[i]-'0';
            i++;
        }
        op.push_back(g*(-1));
        if(ope.size())
            if(ope[ope.size()-1]=='*'||ope[ope.size()-1]=='/'){
                int a=op[op.size()-1];
                op.pop_back();
                int b=op[op.size()-1];
                op.pop_back();
                if(ope[ope.size()-1]=='*')op.push_back(a*b);
                else op.push_back(b/a);
                ope.pop_back();
            }
        if(str[i])ope.push_back(str[i]);
    }
    for(;i<str.length();i++){
        //cout<<"KK";
        if(str[i]=='('){
            string t;
            i++;
            lp++;
            while(lp){
                t+=str[i];
                i++;
                if(str[i]=='(')lp++;
                if(str[i]==')')lp--;
            }
            i++;
            op.push_back(solve(t));
            //cout<<"(): "<<ope[ope.size()-1]<<endl;
            if(ope.size())
            if(ope[ope.size()-1]=='*'||ope[ope.size()-1]=='/'){
                int a=op[op.size()-1];
                op.pop_back();
                int b=op[op.size()-1];
                op.pop_back();
                if(ope[ope.size()-1]=='*')op.push_back(a*b);
                else op.push_back(b/a);
                ope.pop_back();
            }
            if(str[i])ope.push_back(str[i]);
        }
        else if(str[i]>='0'&&str[i]<='9'){
            int g=0;
            while(str[i]>='0'&&str[i]<='9'){
                g=g*10+str[i]-'0';
                i++;
            }
            op.push_back(g);
            if(ope.size())
                if(ope[ope.size()-1]=='*'||ope[ope.size()-1]=='/'){
                    int a=op[op.size()-1];
                    op.pop_back();
                    int b=op[op.size()-1];
                    op.pop_back();
                    if(ope[ope.size()-1]=='*')op.push_back(a*b);
                    else op.push_back(b/a);
                    ope.pop_back();
                }
            if(str[i])ope.push_back(str[i]);
        }
    }
    cout<<"!"<<endl;
    int las=op[op.size()-1];
    op.pop_back();
    while(ope.size()){
        cout<<"las: "<<las<<endl;
        char c=ope[ope.size()-1];
        ope.pop_back();
        if(c=='=')continue;
        int pre=op[op.size()-1];
        cout<<"pre: "<<pre<<endl;
        cout<<ope.size()<<"   c: "<<c<<endl;
        op.pop_back();
        if(c=='+')las=las+pre;
        else las=pre-las;
    }
    cout<<"returned : "<<las<<endl;
    return las;
}

int main(){
    int n;
    cin>>n;
    while(n--){
        string str;
        cin>>str;
        cout<<solve(str)<<endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=3005,INF=1<<29;
typedef string::const_iterator State;

int expr(State &begin);
int term(State &begin);
int factor(State &begin);
int number(State &begin);

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

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

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

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    for(int i=0;i<N;i++){
        string S;cin>>S;
        State a=S.begin();
        cout<<expr(a)<<endl;
    }
}

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

int p;
string expr;

int parseInt()
{
	int ret=0;
	while(isdigit(expr[p]))
	{
		ret*=10;
		ret+=expr[p]-'0';
		p++;
	}
	
	return ret;
}

char parseChr()
{
	char ret=expr[p];
	p++;
	
	return ret;
}

int calc(stack<int>& num, stack<char>& sta)
{
	int r=num.top(); num.pop();
	int l=num.top(); num.pop();
	char e=sta.top(); sta.pop();
	
	if(e=='+') return l+r;
	if(e=='-') return l-r;
	if(e=='*') return l*r;
	
	return l/r;
}

int main()
{
	int N;
	
	map<char, int> tab;
	tab.insert(make_pair('+',1));
	tab.insert(make_pair('-',1));
	tab.insert(make_pair('*',2));
	tab.insert(make_pair('/',2));
	tab.insert(make_pair('(',3));
	tab.insert(make_pair(')',-3));
	
	cin >> N;
	while(N--)
	{	
		p=0;
		cin >> expr;
		
		int nc=0;
		stack<char> sta;
		stack<int> cnt;
		stack<int> num;
		while(expr[p]!='=')
		{
			if(isdigit(expr[p]))
			{
				num.push(parseInt());
			}
			else
			{
				char c=parseChr();
				if(c=='('||c==')') nc+=tab[c];
				else
				{
					while(!sta.empty())
					{
						if(cnt.top()+tab[sta.top()] >= nc+tab[c])
						{
							int ret=calc(num,sta);
							num.push(ret);
							cnt.pop();
						}
						else break;
					}
					
					sta.push(c);
					cnt.push(nc);
				}
			}
		}
		
		while(!sta.empty())
		{
			int ret=calc(num,sta);
			num.push(ret);
		}
		
		cout << num.top() << endl;
	}
}

C++: #include<iostream>
#include<cctype> // isdigit
#include<cassert> // assert
using namespace std;

struct Result{int value,pos;};

int calculate(string expression);
Result equation(string expression,int pos);
Result factor(string expression,int pos);
Result term(string expression,int pos);

int calculate(string expression)
{
  return equation(expression,0).value;
}

Result equation(string expression,int pos)
{
  Result r=factor(expression,pos);
  // Á¸Z
  while(expression[r.pos]=='+' || expression[r.pos]=='-'){
    Result _r=factor(expression,r.pos+1);
    if(expression[r.pos]=='+')r.value += _r.value;
    if(expression[r.pos]=='-')r.value -= _r.value;
    r.pos=_r.pos;
  }
  return r;
}
Result factor(string expression,int pos)
{
  Result r=term(expression,pos);
  // æZ
  while(expression[r.pos]=='*' || expression[r.pos]=='/'){
    Result _r=term(expression,r.pos+1);
    if(expression[r.pos]=='*')r.value *= _r.value;
    if(expression[r.pos]=='/')r.value /= _r.value;
    r.pos=_r.pos;
  }
  return r;
}
Result term(string expression,int pos)
{
  Result r;
  // l
  if(isdigit(expression[pos])){
    int value=0;
    while(isdigit(expression[pos]))value = value*10 + expression[pos++]-'0';
    r.value=value;
    r.pos=pos;
    return r;
  }
  // PZqÌ}CiX
  if(expression[pos]=='-'){
    r=equation(expression,pos+1);
    r.value*=-1;
    return r;
  }
  // Ê
  if(expression[pos]=='('){
    r=equation(expression,pos+1);
    assert(expression[r.pos++]==')');
    return r;
  }
}

int main()
{
  int n;
  string s;
  cin>>n;
  while(n-->0){
    cin>>s;
    s=s.substr(0,s.size()-1);
    cout<<calculate(s)<<endl;
  }
}