Language: C++

#include<iostream>
#include<cctype>
typedef string::const_iterator State;
class ParseError{};

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


int main(void){
  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);
    cout << ans << endl;
  }
  return 0;
}

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=number(begin);

  while(1){
    if(*begin=='*'){
      begin++;
      ret*=factor(begin);
    }
    else if(*begin=='/'){
      begin++;
      ret/=factor(begin);
    }
    else break;
  }
  return ret;
}

int factor(State &begin){
  if(*begin=='('){
    begin++;
    int ret=expression(begin);
    begin++;
  }
  else return number(begin);
}

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

  while(isdigit(*begin)){
    ret*=10;
    ret+=*begin-'0';
    begin++;
  }
  return ret;
}

Compiler output:
a.cc:3:9: error: 'string' does not name a type; did you mean 'stdin'?
    3 | typedef string::const_iterator State;
      |         ^~~~~~
      |         stdin
a.cc:6:16: error: 'State' was not declared in this scope
    6 | int expression(State &begin);
      |                ^~~~~
a.cc:6:23: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
    6 | int expression(State &begin);
      |                       ^~~~~
      |                       std::begin
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:7:10: error: 'State' was not declared in this scope
    7 | int term(State &begin);
      |          ^~~~~
a.cc:7:17: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
    7 | int term(State &begin);
      |                 ^~~~~
      |                 std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:8:12: error: 'State' was not declared in this scope
    8 | int factor(State &begin);
      |            ^~~~~
a.cc:8:19: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
    8 | int factor(State &begin);
      |                   ^~~~~
      |                   std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:9:12: error: 'State' was not declared in this scope
    9 | int number(State &begin);
      |            ^~~~~
a.cc:9:19: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
    9 | int number(State &begin);
      |                   ^~~~~
      |                   std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc: In function 'int main()':
a.cc:14:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   14 |   cin >> N;
      |   ^~~
      |   std::cin
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:18:5: error: 'string' was not declared in this scope
   18 |     string s;
      |     ^~~~~~
a.cc:18:5: note: suggested alternatives:
In file included from /usr/include/c++/14/iosfwd:41,
                 from /usr/include/c++/14/ios:40:
/usr/include/c++/14/bits/stringfwd.h:77:33: note:   'std::string'
   77 |   typedef basic_string<char>    string;
      |                                 ^~~~~~
/usr/include/c++/14/string:76:11: note:   'std::pmr::string'
   76 |     using string    = basic_string<char>;
      |           ^~~~~~
a.cc:19:17: error: 's' was not declared in this scope
   19 |     getline(cin,s);
      |                 ^
a.cc:21:5: error: 'State' was not declared in this scope
   21 |     State begin=s.begin();
      |     ^~~~~
a.cc:22:24: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   22 |     int ans=expression(begin);
      |                        ^~~~~
      |                        std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:22:29: error: 'expression' cannot be used as a function
   22 |     int ans=expression(begin);
      |                             ^
a.cc:23:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   23 |     cout << ans << endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:23:20: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   23 |     cout << ans << endl;
      |                    ^~~~
      |                    std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc: At global scope:
a.cc:28:5: error: redefinition of 'int expression'
   28 | int expression(State &begin){
      |     ^~~~~~~~~~
a.cc:6:5: note: 'int expression' previously defined here
    6 | int expression(State &begin);
      |     ^~~~~~~~~~
a.cc:28:16: error: 'State' was not declared in this scope
   28 | int expression(State &begin){
      |                ^~~~~
a.cc:28:23: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   28 | int expression(State &begin){
      |                       ^~~~~
      |                       std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:45:5: error: redefinition of 'int term'
   45 | int term(State &begin){
      |     ^~~~
a.cc:7:5: note: 'int term' previously defined here
    7 | int term(State &begin);
      |     ^~~~
a.cc:45:10: error: 'State' was not declared in this scope
   45 | int term(State &begin){
      |          ^~~~~
a.cc:45:17: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   45 | int term(State &begin){
      |                 ^~~~~
      |                 std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:62:5: error: redefinition of 'int factor'
   62 | int factor(State &begin){
      |     ^~~~~~
a.cc:8:5: note: 'int factor' previously defined here
    8 | int factor(State &begin);
      |     ^~~~~~
a.cc:62:12: error: 'State' was not declared in this scope
   62 | int factor(State &begin){
      |            ^~~~~
a.cc:62:19: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   62 | int factor(State &begin){
      |                   ^~~~~
      |                   std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~
a.cc:71:5: error: redefinition of 'int number'
   71 | int number(State &begin){
      |     ^~~~~~
a.cc:9:5: note: 'int number' previously defined here
    9 | int number(State &begin);
      |     ^~~~~~
a.cc:71:12: error: 'State' was not declared in this scope
   71 | int number(State &begin){
      |            ^~~~~
a.cc:71:19: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   71 | int number(State &begin){
      |                   ^~~~~
      |                   std::begin
/usr/include/c++/14/bits/range_access.h:114:37: note: 'std::begin' declared here
  114 |   template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
      |                                     ^~~~~