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++: #if 0
????????£?????????????´??????????
?????????pdf????????????????????????????°????????????????????????????
??????????????¨???????????????????????????????????????????????????
#endif
#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
using namespace std;
string S="";
int cur=0;
char readchar()
{
  assert(cur<S.size());
  return S[cur++];
}

char peek()
{
  assert(cur<S.size());
  return S[cur];
}

int digit()
{
  assert(isdigit(peek()));
  int n=readchar()-'0';
  return n;
}

int number()
{
  int n=digit();
  while(cur<S.size()&&isdigit(peek()))
  {
    n=n*10+digit();
  }
  return n;
}

int expression();

int factor()
{
  if(peek()!='(') return number();
  cur+=1;
  int n=expression();
  assert(peek()==')');
  cur+=1;
  return n;
}

int term()
{
  int a=factor();
  while(cur<S.size()&&(peek()=='*'||peek()=='/'))
  {
    char op=readchar();
    int b=factor();
    if(op=='*')
    {
      a*=b;
    }
    else
    {
      a/=b;
    }
  }
  return a;
}

int expression()
{
  int sum=term();
  while(cur<S.size()&&(peek()=='+'||peek()=='-'))
  {
    char op=readchar();
    int b=term();
    if(op=='+')
    {
      sum+=b;
    }
    else
    {
      sum-=b;
    }
  }
  return sum;
}



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++: //Name: Smart Calculator
//Level: 2
//Category: 構文解析
//Note:

/**
 * オーソドックスな四則演算の構文解析。
 *
 * オーダーは O(|S|)。
 */
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>

using namespace std;

typedef string::const_iterator Iterator;

void skip(Iterator &it, char c) {
    if(*it != c) {
        cout << "Expected " << c << " but got " << *it << endl;
        cout << "Parse error near: ";
        while(*it) {
            cout << *it;
            ++it;
        }
        cout << endl;
        abort();
    }
    ++it;
}

long long factor(Iterator&);
long long term(Iterator&);

long long number(Iterator &it) {
    long long val = 0;
    while(isdigit(*it)) {
        val *= 10;
        val += *it - '0';
        ++it;
    }
    return val;
}

long long expr(Iterator &it) {
    long long lhs = term(it);
    while(*it == '+' || *it == '-') {
        const char op = *it;
        skip(it, op);
        const long long rhs = term(it);
        if(op == '+') lhs += rhs;
        else lhs -= rhs;
    }
    return lhs;
}

long long term(Iterator &it) {
    long long lhs = factor(it);
    while(*it == '*' || *it == '/') {
        const char op = *it;
        skip(it, op);
        const long long rhs = factor(it);
        if(op == '*') lhs *= rhs;
        else lhs /= rhs;
    }
    return lhs;
}

long long factor(Iterator &it) {
    if(*it == '(') {
        skip(it, '(');
        const long long val = expr(it);
        skip(it, ')');
        return val;
    } else {
        return number(it);
    }
}

bool solve() {
    string line;
    cin >> line;
    Iterator it = line.begin();
    cout << expr(it) << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    int N;
    cin >> N;
    while(N--) solve();
    return 0;
}

C++: #include<iostream>
#include<string>
#include<stack>
#include<sstream>
#include<vector>
using namespace std;
int main(){
  stringstream ss;
  int n;
  string line;
  for(cin>>n;n>0;n--){
    ss.str("");
    ss.clear(stringstream::goodbit);
    cin>>line;
    vector<int> form,f_nums;
    vector<char> f_signs;
    if(line[0]=='-')line = "0"+line;
    ss<<line;
    stack<char> sg;
    int num;
    char sign;
    for(int i=0;i<line.size();i++){
      if('0'<=ss.str()[i]&&ss.str()[i]<='9'){
	ss>>num;
	for(int d=10;d<=num;i++)d*=10;
	f_nums.push_back(num);
	form.push_back(f_nums.size()-1);
      }
      else{
	ss>>sign;
	if(sign=='=')break;
	if(sign==')'){
	  while(sg.top()!='('){
	    f_signs.push_back(sg.top());
	    form.push_back(-f_signs.size());
	    sg.pop();
	  }
	  sg.pop();
	}
	else{
	  if(sign!='('){
	    while(!sg.empty()&&sg.top()!='('&&((sign=='+'||sign=='-')||(sg.top()=='*'||sg.top()=='/'))){
	      f_signs.push_back(sg.top());
	      form.push_back(-f_signs.size());
	      sg.pop();
	    }
	  }
	  sg.push(sign);
	}
      }
    }
    while(!sg.empty()){
      f_signs.push_back(sg.top());
      form.push_back(-f_signs.size());
      sg.pop();
    }
    stack<int> calc;
    for(int i=0;i<form.size();i++){
      if(form[i]>=0){
	calc.push(f_nums[form[i]]);
      }
      else{
	double a,b,c;
	b = calc.top();
	calc.pop();
	a = calc.top();
	calc.pop();
	if(f_signs[-form[i]-1]=='+')c = a+b;
	if(f_signs[-form[i]-1]=='-')c = a-b;
	if(f_signs[-form[i]-1]=='*')c = a*b;
	if(f_signs[-form[i]-1]=='/')c = a/b;
	calc.push(c);
      }
    }
    cout<<calc.top()<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <vector>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

void calc(string st, stack<ll> &s) {	
	if(st == "*") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(a * b);
	} else if(st == "+") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(a + b);
	} else if(st == "-") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(b - a);
	} else if(st == "/") {
		int a = s.top();
		s.pop();
		int b = s.top();
		s.pop();
		s.push(b / a);
	} else {
		s.push(atoi(st.c_str()));
	}
}
int getPriority(string s) {
	if(s == "(") {
		return 5;
	} else if(s == "*" || s == "/") {
		return 3;
	} else if(s == "+" || s == "-") {
		return 2;
	} else if(s == ")") { 
		return 1;
	} else return 4;
}

int main() {
	int n;
	cin >> n;
	while(n--) {
		string str;
		cin >> str;
		str.erase(--str.end());
		
		vector<string> v;
		
		int f = 0;
		rep(i, str.size()) {			
			if(isdigit(str[i])) {
				f++;
			} else {
				if(f) {
					string st;
					rep(j,f) {
						st += str[i - f + j];
					}
					v.push_back(st);
					string st2;
					st2 += str[i];
					v.push_back(st2);
					f = 0;
				} else {
					string st3;
					st3 += str[i];
					v.push_back(st3);
				}
			}
		}
		stack<string> s;
		vector<string> nv;
		stack<ll> ret;
		int p = 0;
		rep(i,v.size()) {
			p = getPriority(v[i]);
			while(!s.empty() && getPriority(s.top()) > p && s.top() != "(") {
				nv.push_back(s.top());
				s.pop();
			}
			if(v[i] == ")") {
				s.pop();
			} else {
				s.push(v[i]);
			}
		}
		while(!s.empty()) {
			nv.push_back(s.top());
			s.pop();
		}
		rep(i,nv.size()) {
			calc(nv[i], ret);
		}
		cout << ret.top() << endl;
	}
	return 0;
}