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

string str,t;

string calc(string s){
	
	vector<char> otr;
	otr.reserve(1000);
	vector<int> ond;
	ond.reserve(1000);
	string tmp;
	size_t now = 0;
	
	while( ~s.find_first_of("*/-+=",now) ){
		tmp = s.substr(now,s.find_first_of("*/-+=",now)-now);
		ond.push_back( atoi(tmp.c_str() ) );
		otr.push_back( s[s.find_first_of("*/-+=",now)] );
		now = s.find_first_of("*/-+=",now)+1;
	}

	for(int i=0;i<otr.size();i++){
		if(otr[i]=='*'){
			ond[i] = ond[i] * ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}else if(otr[i]=='/'){
			//ond[i] = ond[i] / ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}
	}

	/*cout << ond[0];
	for(int j=0;j<otr.size();j++){
		if(otr[j]=='=')break;
		cout << " " << otr[j] << " ";
		cout << ond[j+1];
	}
	cout << endl;*/
	
	for(int i=0;i<otr.size();i++){
		if(otr[i]=='+'){
			ond[i] = ond[i] + ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}else if(otr[i]=='-'){
			ond[i] = ond[i] - ond[i+1] ;
			ond.erase(ond.begin()+i+1) ;
			otr.erase(otr.begin()+i)   ;
			i--;
		}
	}
	stringstream ret;
	ret << ond[0];
	return ret.str();
}

string parent(string s){	
	int st,en;
	while( ~s.find("(") ){
		st = s.find("(");
		en = s.find(")");
		t = s.substr(st+1,en-st-1);
		s.replace( st , en-st+1 , parent(t+string("=")));
	}
	return calc(s);
}

int main(){
	int n;
	cin >> n;
	while(cin >> str){
		/*
		if(~s.find("(")){
			st = s.find("(");
			en = s.rfind(")");
			t = s.substr(st+1,en-st-1);
		}*/
		cout << parent(str) << endl;
	}
}

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

using namespace std;

int prior[128];

int parse(string s)
{
	if(s[0]=='(' && s[s.length()-1]==')'){
		bool f=true;
		for(int i=1,d=1;i<s.length()-1;i++){
			if     (s[i]=='(')	d++;
			else if(s[i]==')')	d--;
			if(d==0){	f=false;	break;	}
		}
		if(f)	return parse(s.substr(1,s.length()-2));
	}

	int divprr=3,divpos=10000000;
	for(int i=0,d=0;i<s.length();i++){
		if     (s[i]=='(')	d++;
		else if(s[i]==')')	d--;

		else if(d==0 && prior[s[i]]!=0){
			if(i==0 && prior[s[i]]==1)	continue;
			if(divprr>prior[s[i]])
				divprr=prior[s[i]],divpos=i;
		}
	}

	if(divpos==10000000)	return atof(s.c_str());

	switch(s[divpos]){
		case '+': return parse(s.substr(0,divpos)) + parse(s.substr(divpos+1));
		case '-': return parse(s.substr(0,divpos)) - parse(s.substr(divpos+1));
		case '*': return parse(s.substr(0,divpos)) * parse(s.substr(divpos+1));
		case '/': return parse(s.substr(0,divpos)) / parse(s.substr(divpos+1));
	}
}

int main()
{
	prior['+']=prior['-']=1;
	prior['*']=prior['/']=2;

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

	return 0;
}

C++: //https://gist.github.com/draftcode/1357281
#include <string>
#include <cctype>
#include <iostream>
typedef std::string::iterator State;
class ParseError {};

int number(State &begin);
int factor(State &begin);
int term(State &begin);
int expression(State &begin);
void consume(State &begin, char expected){
	if(*begin == expected){
		begin++;
	}else{
		std::cerr << "Expected '" << expected << "' but got '"<<*begin << "'"<<std::endl;
		std::cerr << "Rest string is '";
		while(*begin){
			std::cerr << *begin++;
		}
		std::cerr<<"'"<<std::endl;
		throw ParseError();
	}
}

int main(void){
	int N;
	std::cin >> N;
	std::cin.ignore();
	while(N--){
		std::string s;
		std::getline(std::cin, s);
		//std::cin>>s;
		State begin = s.begin();
		int ans = expression(begin);
		//consume(begin, '=');
		std::cout << ans << std::endl;
	}
	return 0;
}

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,'(');
		begin++;
		int ret = expression(begin);
		//consume(begin,')');
		begin++;
	}else{
		return number(begin);
	}
	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 expression(State &begin){
	int ret = term(begin);

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

C++: #include <bits/stdc++.h>

using namespace std;

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

int expr(string& s, int& i);
int term(string& s, int& i);
int factor(string& s, int& i);
int number(string& s, int& i);

int expr(string& s, int& i) {
	int val = term(s, i);
	while (s[i] == '+' || s[i] == '-') {
		char op = s[i++];
		int val2 = term(s, i);
		if (op == '+') val += val2;
		else val -= val2;
	}
	return val;
}

int term(string& s, int& i) {
	int val = factor(s, i);
	while (s[i] == '*' || s[i] == '/') {
		char op = s[i++];
		int val2 = factor(s, i);
		if (op == '*') val *= val2;
		else val /= val2;
	}
	return val;
}

int factor(string& s, int& i) {
	if (isdigit(s[i])) return number(s, i);
	
	i++;
	int res = expr(s, i);
	i++;
	return res;
}

int number(string& s, int& i) {
	int num = s[i++] - '0';
	while (isdigit(s[i])) num = num*10 + s[i++] - '0';
	return num;
}

int main() {
	int n;
	cin >> n;
	while (n--) {
		string str;
		cin >> str;
		str.erase(str.end() - 1);
		int i = 0;
		cout << expr(str, i) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<stack>
#include<string>
#include <sstream>

using namespace std;
string s;
int idx;
int term();
int expr();
int fact();
int number();

// <term> = <fact> { (‘*’|‘/’) <fact> } 
int term(){
  int res = fact();
  while(s[idx] == '*' || s[idx] == '/'){
    char op = s[idx++];
    int tmp = fact(); 
    if(op == '*')
      res *= tmp;
    else res /= tmp;
  }
  return res;
}


// <expr> = <term> { (‘+’|‘-’) <term> }
int expr(){
  int res = term();
  while(s[idx] == '+' || s[idx] == '-'){
    char op = s[idx++];
    int tmp = term();
    if(op == '+') res += tmp;
    else res -= tmp;
  }
  return res;
}


// <number> = { <digit> }
// <digit> = ‘0’ | ‘1’ | ... | ‘9’
int number(){
  int res = 0;
  while('0' <= s[idx] && s[idx] <= '9'){
    res = res*10 + s[idx] - '0';
    idx++;
  }
  return res;
}

// <fact> = ‘(’ <expr> ‘)’ | <number> 
int fact(){ 
  int res; 
  if(s[idx] == '('){
    idx++; 
    res = expr();
    //assert( s[idx] == ')' ); 
    idx++;
  } 
  else{ 
    res = number(); 
  } 
  return res;
}


int main()
{
  int n;
  
  cin>>n;
  for(;n--;)
    {
      idx=0;
      cin>>s;
      cout << expr()<<endl;
    }
}