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>
#define int long long
using namespace std;

// exp1 = exp2 [ ('+'|'-') exp2 ]*
// exp2 = exp3 [ ('*'|'/') exp3 ]*
// exp3 = '(' exp1 ')' | number
int exp1(const string& s, int& i);
int exp2(const string& s, int& i);
int exp3(const string& s, int& i);
int number(const string& s, int& i);
int exp1(const string& s, int& i) {
  int acc = exp2(s, i);
  while (1) {
    if (s[i] == '+') acc += exp2(s, ++i);
    else if (s[i] == '-') acc -= exp2(s, ++i);
    else return acc;
  }
}
int exp2(const string& s, int& i) {
  int acc = exp3(s, i);
  while (1) {
    if (s[i] == '*') acc *= exp3(s, ++i);
    else if (s[i] == '/') acc /= exp3(s, ++i);
    else return acc;
  }
}
int exp3(const string& s, int& i) {
  if (s[i] == '(') {
    int ret = exp1(s, ++i);
    assert(s[i] == ')');
    i++;
    return ret;
  }
  return number(s, i);
}
int number(const string& s, int& i) {
  int acc = 0;
  while (isdigit(s[i])) {
    acc = acc * 10 + (s[i++] - '0');
  }
  return acc;
}

void solve() {
  string s; cin >> s;
  int i = 0;
  cout << exp1(s, i) << endl;
  assert(s[i] == '=');
}
signed main() {
  int T; cin >> T;
  while (T--) solve();
}

C++: #include<iostream>
using namespace std;
string str;
int p;
int exp();
int term();
int factor();


int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    p=0;  
    cin>>str;
    cout<<exp()<<endl;
  }
  return 0;
}


int exp(){
  int val=term();
  while(str[p]=='+'||str[p]=='-'){
    if(str[p]=='+'){
      p++;
      val+=term();
    }
    else if(str[p]=='-'){
      p++;
      val-=term();
    }
  }
  return val;
}


int term(){
  
  int val=factor();
  while(str[p]=='*'||str[p]=='/'){
    if(str[p]=='*'){
      p++;
      val*=factor();
    }
    else if(str[p]=='/'){
      p++;
      val/=factor();
    }
  }
  return val;
}


int factor(){
  int val=0;
  
  if(str[p]=='('){
    p++;    
    val=exp();
    p++;
  }
  else{
    while('0'<=str[p]&&str[p]<='9'){
      val*=10;
      val+=(str[p]-'0');   
      p++;
    }
  }
  return val;
}

C++: #include <string>
#include <cctype>
#include <iostream>
using namespace std;
typedef string::const_iterator State;
class ParseError{};

int number(State&);
int term(State&);
int expression(State&);
int factor(State&);

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 factor(State& begin){
  int ret;
  if(*begin == '('){
    ++begin;
    ret = expression(begin);
    ++begin;
  }
  else ret = number(begin);
  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;
}

int main(){
  int n;
  cin >> n;
  cin.ignore();
  while(n--){
    string s;
    getline(cin,s);
    State b = s.begin();
    int ans = expression(b);
    cout << ans << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;

int expression(State &begin);

int term(State &begin);

int factor(State &begin);

int number(State &begin);

void consume(State &begin,char expected);

int main(){
  int n;
  cin>>n;
  cin.ignore();
  for(int i=0;i<n;i++){
    string s;
    getline(cin,s);

    State begin = s.begin();
    int ans=expression(begin);
    consume(begin,'=');
    cout<<ans<<endl;
  }

}


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


int term(State &begin){
  int ret = number(begin);

  for(;;){
    if(*begin =='*'){
      consume(begin,'*');
      ret *= factor(begin);
    }
    else if(*begin =='/'){
      consume(begin,'/');
      ret /= factor(begin);
    }
    else break;
  }

  return ret;
}


int expression(State &begin){
  int ret = term(begin);

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



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;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;

int expression(State &begin);

int term(State &begin);

int factor(State &begin);

int number(State &begin);

void consume(State &begin,char expected);

int main(){
  int n;
  cin>>n;
  cin.ignore();
  for(int i=0;i<n;i++){
    string s;
    getline(cin,s);

    State begin = s.begin();
    int ans=expression(begin);
    consume(begin,'=');
    cout<<ans<<endl;
  }

}


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


int term(State &begin){
  int ret = number(begin);

  for(;;){
    if(*begin =='*'){
      consume(begin,'*');
      ret *= factor(begin);
    }
    else if(*begin =='/'){
      consume(begin,'/');
      ret /= factor(begin);
    }
    else break;
  }

  return ret;
}


int expression(State &begin){
  int ret = term(begin);

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



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;
  }
}