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>
#include<algorithm>
using namespace std;
#define INF (1<<24)

bool isNum(char ch){return ('0'<=ch&&ch<='9');}

struct calcStr{
  string s;
  int pos,len;
  bool flag;
  void init(){ pos=0;len=s.size()-1; flag=false; }

  int head2Num(){
    int res=0;

    //if(pos+1<len&&s[pos]=='0'&&isNum(s[pos+1]))flag=true;
    //if(!isNum(s[pos])){flag=true;}

    while(pos<len){
      if(isNum(s[pos])){
	res*=10;
	res+=(s[pos]-'0');
      }else break;
      pos++;
    }
    return res;
  }
  
  int getNum(){
    int res=head2Num(),z;
    if(pos==len)return res;
    else if(s[pos]=='*'){
      pos++;
      return res*getNum();
    }else if(s[pos]=='/'){
      pos++;
      z=getNum();
      if(z==0){flag=true;z=1;}
      else if(res%z!=0)flag=true;
      return res/z;
    }
    return res;
  }
  
  int getAns(){
    int res=getNum(),num;
    while(1){
      if(pos==len)break;
      char ch=s[pos++];
      num=getNum();
      if(ch=='+')res+=num;
      else if(ch=='-')res-=num;
    }
    if(flag)return INF;
    else return res;
  }
};

int main(){
  int Tc;cin>>Tc;
  calcStr a;
  while(Tc--){
    cin>>a.s;
    a.init();
    cout<<a.getAns()<<endl;
  }
  return 0;
}

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

using namespace std;

struct Result {
        int value, p;
};

#define PARSER_DECL(name) \
        Result name (const string &s, int p)

PARSER_DECL(expr);
PARSER_DECL(term);
PARSER_DECL(factor);
PARSER_DECL(number);

PARSER_DECL(expr){
        Result r = term(s, p);
        while(s[r.p] == '+' || s[r.p] == '-'){
                Result q = term(s, r.p + 1);
                if(s[r.p] == '+'){
                        r.value += q.value;
                        r.p = q.p;
                }else if(s[r.p] == '-'){
                        r.value -= q.value;
                        r.p = q.p;
                }
        }
        return r;
}

PARSER_DECL(term){
        Result r = factor(s, p);
        while(s[r.p] == '*' || s[r.p] == '/'){
                Result q = factor(s, r.p + 1);
                if(s[r.p] == '*'){
                        r.value *= q.value;
                        r.p = q.p;
                }else if(s[r.p] == '/'){
                        r.value /= q.value;
                        r.p = q.p;
                }
        }
        return r;
}

PARSER_DECL(factor){
        Result r;
        if(s[p] == '('){
                r = expr(s, p + 1);
                ++r.p;
        }else{
                r = number(s, p);
        }
        return r;
}

PARSER_DECL(number){
        Result r;
        r.value = 0;
        r.p = p;
        while(isdigit(s[r.p])){
                r.value = (r.value * 10) + (s[r.p] - '0');
                ++r.p;
        }
        return r;
}

int main(){
        int n;
        cin >> n;
        while(n--){
                string s;
                cin >> s;
                s.resize(s.size() - 1);
                cout << expr(s, 0).value << endl;
        }
        return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <utility>
using namespace std;

typedef pair<int, int> Pair;

int _;
int n;
char buf[11451419];

Pair EvalElem(int pos);
Pair EvalTerm(int pos);
Pair EvalExp(int pos);

Pair EvalElem(int pos) {
  if (buf[pos] == '(') {
    Pair p = EvalExp(pos+1);
    return Pair(p.first, p.second+1);
  }

  char c = buf[pos];

  if ('0' <= c && c <= '9') {
    char *next;
    int res = strtol(buf+pos, &next, 10);
    return Pair(res, next-buf);
  }

  return Pair(-1, -1);
}

Pair EvalTerm(int pos) {
  Pair p = EvalElem(pos);
  assert(p.second != -1);

  pos = p.second;
  if (buf[pos] == '*') {
    Pair q = EvalExp(pos+1);
    return Pair(p.first*q.first, q.second);
  }

  if (buf[pos] == '/') {
    Pair q = EvalExp(pos+1);
    return Pair(p.first/q.first, q.second);
  }

  return p;
}

Pair EvalExp(int pos) {
  Pair p = EvalTerm(pos);
  pos = p.second;
  int res = p.first;
  while (1) {
    if (buf[pos] == '=' || buf[pos] == ')') {
      return Pair(res, pos);
    }

    Pair q = EvalTerm(pos+1);
    if (buf[pos] == '+') res += q.first;
    else if (buf[pos] == '-') res -= q.first;
    else assert(0);

    pos = q.second;
  }

}

int main() {
  scanf("%d", &_);
  while (_--) {
    scanf("%s", buf);
    n = strlen(buf);

    Pair res = EvalExp(0);
    assert(res.second == n-1);
    printf("%d\n", res.first);
  }
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int main(){

	int n,tmp,op1,work,count;
	char line[101],calc;
	stack<int> NUM,work_num;
	stack<char> OP,work_op;

	bool numFLG,negFLG;

	scanf("%d",&n);

	for(int i = 0; i < n; i++){
		scanf("%s",line);

		tmp = 0;
		numFLG = false;
		negFLG = false;

		for(int k = 0; line[k] != '\0'; k++){
			if(line[k] >= '0' && line[k] <= '9'){
				numFLG = true;
				tmp = 10*tmp + (line[k] - '0');

			}else{

				if(numFLG == true){

					if(negFLG){
						tmp = -1*tmp;
						negFLG = false;
					}

					if(OP.empty() == false && (OP.top() == '*' || OP.top() == '/')){
						calc = OP.top();
						OP.pop();
						op1 = NUM.top();
						NUM.pop();

						if(calc == '*'){
							NUM.push(tmp*op1);
						}else{
							NUM.push(op1/tmp);
						}
					}else{
						NUM.push(tmp);
					}

					numFLG = false;
					tmp = 0;
				}

				if(line[k] == '+' ||line[k] == '*' || line[k] == '/' || line[k] == '('){
					OP.push(line[k]);
				}else if(line[k] == '-'){
					if(k == 0){
						if(line[k+1] != '('){
							negFLG = true;
						}else{
							NUM.push(-1);
							OP.push('*');
						}
					}else if(line[k-1] == '(' && line[k+1] == '('){
						NUM.push(-1);
						OP.push('*');
					}else if(line[k-1] == '+' || line[k-1] == '-' || line[k-1] == '*' || line[k-1] == '/' || line[k-1] == '('){
						negFLG = true;
					}else{
						OP.push('-');
					}

				}else if(line[k] == ')'){

					work = NUM.top();
					NUM.pop();
					work_num.push(work);

					count = 0;

					while(true){
						calc = OP.top();
						OP.pop();
						if(calc == '(')break;

						count++;

						work_op.push(calc);

						work = NUM.top();
						NUM.pop();
						work_num.push(work);
					}

					if(count == 0){
						work = work_num.top();
						work_num.pop();
					}else{

						work = work_num.top();
						work_num.pop();

						while(!work_num.empty()){
							calc = work_op.top();
							work_op.pop();

							if(calc == '+'){
								work += work_num.top();
							}else if(calc == '-'){
								work -= work_num.top();
							}else if(calc == '*'){
								work *= work_num.top();
							}else{
								work /= work_num.top();
							}
							work_num.pop();
						}
					}

					NUM.push(work);

				}else{

					work = NUM.top();
					NUM.pop();
					work_num.push(work);

					while(!NUM.empty()){
						calc = OP.top();
						OP.pop();

						work_op.push(calc);

						work = NUM.top();
						NUM.pop();
						work_num.push(work);
					}

					work = work_num.top();
					work_num.pop();

					while(!work_num.empty()){
						calc = work_op.top();
						work_op.pop();

						if(calc == '+'){
							work += work_num.top();
						}else if(calc == '-'){
							work -= work_num.top();
						}else if(calc == '*'){
							work *= work_num.top();
						}else{
							work /= work_num.top();
						}
						work_num.pop();
					}

					printf("%d\n",work);
				}
			}
		}

	}


	return 0;
}