Language: C++

string s;
bool f;
int r1, r2;
char r3;
  
int toInt(string s){return atoi(s.c_str());}
  
bool check(int a){
  if(a < 0 || a > 9999){
    f = true;
    return true;
  }
  return false;
}
  
int main(){
  while(getline(cin,s)){
    s = s.substr(0,s.size()-1);
    r1 = r2 = 0;
    r3 = '?';
    int pos = 0;    
    f = false;
  
    string num = "";
    for(; pos<s.size(); pos++){
      if(s[pos] >= '0' && s[pos] <= '9') num += s[pos];
      else {r3 = s[pos++]; break;}
    }
  
    if(num.size() > 4){cout << "E" << endl; continue;}    
    r1 = toInt(num);
  
  
    while(pos < s.size()){
      if(f)break;
      num = "";
  
      for(; pos<s.size(); pos++){
    if(s[pos] >= '0' && s[pos] <= '9') num += s[pos];
    else {r3 = s[pos++]; break;}
      }
  
      r2 = toInt(num);
      if(f)break;
  
      if(r3 == '+') r1 += r2;
      if(r3 == '-') r1 -= r2;
      if(r3 == '*') r1 *= r2;
      if(check(r1)) break;
      r2 = 0;
  
    }
  
    if(f) cout << "E" << endl;
    else cout << r1 << endl;
  
  }
  return 0;
}

Compiler output:
a.cc:1:1: error: 'string' does not name a type
    1 | string s;
      | ^~~~~~
a.cc:6:11: error: 'string' was not declared in this scope
    6 | int toInt(string s){return atoi(s.c_str());}
      |           ^~~~~~
a.cc: In function 'int main()':
a.cc:17:17: error: 'cin' was not declared in this scope
   17 |   while(getline(cin,s)){
      |                 ^~~
a.cc:17:21: error: 's' was not declared in this scope
   17 |   while(getline(cin,s)){
      |                     ^
a.cc:17:9: error: 'getline' was not declared in this scope
   17 |   while(getline(cin,s)){
      |         ^~~~~~~
a.cc:24:5: error: 'string' was not declared in this scope
   24 |     string num = "";
      |     ^~~~~~
a.cc:26:42: error: 'num' was not declared in this scope; did you mean 'enum'?
   26 |       if(s[pos] >= '0' && s[pos] <= '9') num += s[pos];
      |                                          ^~~
      |                                          enum
a.cc:30:8: error: 'num' was not declared in this scope; did you mean 'enum'?
   30 |     if(num.size() > 4){cout << "E" << endl; continue;}
      |        ^~~
      |        enum
a.cc:30:24: error: 'cout' was not declared in this scope
   30 |     if(num.size() > 4){cout << "E" << endl; continue;}
      |                        ^~~~
a.cc:30:39: error: 'endl' was not declared in this scope
   30 |     if(num.size() > 4){cout << "E" << endl; continue;}
      |                                       ^~~~
a.cc:31:16: error: 'num' was not declared in this scope; did you mean 'enum'?
   31 |     r1 = toInt(num);
      |                ^~~
      |                enum
a.cc:31:19: error: 'toInt' cannot be used as a function
   31 |     r1 = toInt(num);
      |                   ^
a.cc:43:17: error: 'toInt' cannot be used as a function
   43 |       r2 = toInt(num);
      |            ~~~~~^~~~~
a.cc:54:11: error: 'cout' was not declared in this scope
   54 |     if(f) cout << "E" << endl;
      |           ^~~~
a.cc:54:26: error: 'endl' was not declared in this scope
   54 |     if(f) cout << "E" << endl;
      |                          ^~~~
a.cc:55:10: error: 'cout' was not declared in this scope
   55 |     else cout << r1 << endl;
      |          ^~~~
a.cc:55:24: error: 'endl' was not declared in this scope
   55 |     else cout << r1 << endl;
      |                        ^~~~