class TStr2PPN { AnsiString instr, outstr; //input & output strings char curc; //the current character int iin; //the index of the input string char nextChar(); //get the next character void begin(); //handle plus & minus void mult_div(); //handle multiplication & division void symbol(); //handle characters & brackets public: TStr2PPN() { //constructor iin = 1; } void convert(char *str); //convert to PPN AnsiString get_outstr(); //get the output string }; //get the next character inline char TStr2PPN::nextChar() { if(iin <= instr.Length()) return curc = instr[iin++]; return curc = '\0'; } //get the output string inline AnsiString TStr2PPN::get_outstr(){return outstr;} //convert to PPN void TStr2PPN::convert(char *str) { try { instr = str; outstr.SetLength(0); iin = 1; nextChar(); //begin the convertation begin(); if(iin != (instr.Length()+1) || curc != '\0') { throw Exception("Syntax error"); } if(!isalpha(instr[instr.Length()]) && instr[instr.Length()]!=')') { throw Exception("Syntax error"); } } catch(...) {throw;} } //handle plus & minus void TStr2PPN::begin() { try { mult_div(); while(curc=='+' || curc=='-') { char temp = curc; nextChar(); mult_div(); outstr += temp; } } catch(...) {throw;} } //handle multiplication & division void TStr2PPN::mult_div() { try { symbol(); while(curc=='*' || curc=='/') { char temp = curc; nextChar(); symbol(); outstr += temp; } } catch(...) {throw;} } //handle characters void TStr2PPN::symbol() { try { if(curc=='(') { nextChar(); begin(); if(curc!=')') { throw Exception("Error: wrong number of brackets"); } else nextChar(); } else if(isalpha(curc)) { outstr += curc; nextChar(); } else {throw Exception("Syntax error");} } catch(...) {throw;} }
(a+b)/(c+d)
prog.cpp:2:5: error: ‘AnsiString’ does not name a type AnsiString instr, outstr; //input & output strings ^~~~~~~~~~ prog.cpp:17:5: error: ‘AnsiString’ does not name a type AnsiString get_outstr(); //get the output string ^~~~~~~~~~ prog.cpp: In member function ‘char TStr2PPN::nextChar()’: prog.cpp:23:14: error: ‘instr’ was not declared in this scope if(iin <= instr.Length()) return curc = instr[iin++]; ^~~~~ prog.cpp: At global scope: prog.cpp:28:8: error: ‘AnsiString’ does not name a type inline AnsiString TStr2PPN::get_outstr(){return outstr;} ^~~~~~~~~~ prog.cpp: In member function ‘void TStr2PPN::convert(char*)’: prog.cpp:33:7: error: ‘instr’ was not declared in this scope instr = str; ^~~~~ prog.cpp:34:7: error: ‘outstr’ was not declared in this scope outstr.SetLength(0); ^~~~~~ prog.cpp:40:40: error: ‘Exception’ was not declared in this scope throw Exception("Syntax error"); ^ prog.cpp:42:40: error: ‘isalpha’ was not declared in this scope if(!isalpha(instr[instr.Length()]) && instr[instr.Length()]!=')') { ^ prog.cpp:43:40: error: ‘Exception’ was not declared in this scope throw Exception("Syntax error"); ^ prog.cpp: In member function ‘void TStr2PPN::begin()’: prog.cpp:57:11: error: ‘outstr’ was not declared in this scope outstr += temp; ^~~~~~ prog.cpp: In member function ‘void TStr2PPN::mult_div()’: prog.cpp:71:11: error: ‘outstr’ was not declared in this scope outstr += temp; ^~~~~~ prog.cpp: In member function ‘void TStr2PPN::symbol()’: prog.cpp:84:62: error: ‘Exception’ was not declared in this scope throw Exception("Error: wrong number of brackets"); ^ prog.cpp:89:25: error: ‘isalpha’ was not declared in this scope if(isalpha(curc)) { ^ prog.cpp:90:13: error: ‘outstr’ was not declared in this scope outstr += curc; ^~~~~~ prog.cpp:93:46: error: ‘Exception’ was not declared in this scope else {throw Exception("Syntax error");} ^
Standard output is empty