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 <bits/stdc++.h>
using namespace std;

int calc(char *s, char *end)
{
	/*for (char *p = s; p != end; p++) printf("%c", *p);
	puts("");*/
	
	bool f = false;
	
	vector<int> st;
	vector<char> op;
	
	char *p = s;
	while (p != end){
		if (!f) if (*p == '('){
			char *e;
			for (e = p + 1; *e != ')'; e++);
			st.push_back(calc(p + 1, e));
			p = e;
		}
		if (f) if (*p == '+' || *p == '-' || *p == '*' || *p == '/'){
			op.push_back(*p);
			p++;
			f ^= 1;
			continue;
		}
		if (!f) if (*p >= '0' && *p <= '9'){
			int n = atoi(p);
			st.push_back(n);
			stringstream ss;
			ss << n;
			p += ss.str().size() - 1;
		}
		if (!f) if (*p == '-'){
			int n = atoi(p);
			st.push_back(n);
			stringstream ss;
			ss << n;
			p += ss.str().size() - 1;
			//printf("%s\n", ss.str().c_str());
		}
		if (op.size() && (op.back() == '*' || op.back() == '/')){
			int b = st.back(); st.pop_back();
			int a = st.back(); st.pop_back();
			if (op.back() == '*') a *= b;
			if (op.back() == '/') a /= b;
			st.push_back(a);
			op.pop_back();
		}
		p++;
		f = !f;
		/*printf("__");
		for (auto a : st) printf("%d ", a);
		puts("");*/
	}
	
	while (op.size()){
		int t = st.front(); st.erase(st.begin());
		/*if (st.size() == 0){
			if (op.front() == '-') st.push_back(-t);
			else st.push_back(t);
			op.erase(op.begin());
			break;
		}*/
		if (op.front() == '+') st[0] = t + st[0];
		if (op.front() == '-') st[0] = t - st[0];
		op.erase(op.begin());
	}
	
	return st[0];
}

int main()
{
	int n;
	char str[1024];
	
	scanf("%d", &n);
	for (int i = 0; i < n; i++){
		scanf("%s", str);
		str[strlen(str) - 1] = '\0';
		printf("%d\n", calc(str, str + strlen(str)));
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cctype>

using namespace std;

string s;
 
typedef string::const_iterator State;
int expression(State&);
int term(State&);
int number(State&);
int factor(State&);
 
int expression(State &begin){
  int ret = term(begin);
  while(1){
    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);
  while(1){
    if(*begin == '*'){
      begin++;
      ret *= factor(begin);
    }
    else if(*begin == '/'){
      begin++;
      int tmp = factor(begin);
      ret /= tmp;
    }
    else break;
  }
  return ret;
}
 
int number(State &begin){
  int ret = 0;
  while(isdigit(*begin)){
    ret *= 10;
    ret += *begin-'0';
    begin++;
  }
  return ret;
}
 
int factor(State &begin){
  if(*begin == '('){
    begin++;
    int ret = expression(begin);
    begin++;
    return ret;
  }
  else return number(begin);
}

int main(){
  int n;
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> s;
    State ss = s.begin();
    int ans = expression(ss);
    cout << ans << endl;
  }
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;
typedef string::const_iterator State;
class ParseError{};

int factor(State &);

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

int number(State &begin){
  int ret=0;
  while(isdigit(*begin)){
    ret*=10;
    ret+=*begin-'0';
    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 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);
  }
}

signed main(){
  int n;
  cin>>n;
  cin.ignore();
  REP(i,n){
    string s;
    getline(cin,s);
    State begin=s.begin();
    int ans=expr(begin);
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include"bits/stdc++.h"
using namespace std;

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1)cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1)cout<<#x<<":"<<x<<endl;
#define ll long long

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

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

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		int num = 0;
		cout << formula(s, num) << endl;
	}
	return 0;
}

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

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

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

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