///////////////////////////////////////////////////////////////////// // display.cpp - generates formatted strings from semiExp objects // // ver 1.0 // // // // Language: Visual C++, ver 7.0 // // Platfrom: Dell Dimension 8100, Windows 2000, SP 2.0 // // Application: Prototype for CSE687 Pr#2, Spring 2003 // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// #include "display.h" //----< pull class::name from semiExp >------------------------ std::string display::functionName(semiExp &se) { size_t last = se.find("(") - 1; size_t first = last; if(last == se.length()) return "error in display::functionName"; // if this is operator collect operator parens size_t len = se.find("operator"); if(len < se.length()-1) { first = len; if(se[len+1] == "(") last = se.find(")",last+1); else last = se.find("(") - 1; } // if this is a member function collect class name if(first > 0 && se[first-1]=="~") --first; if(first > 1 && se[first-1]=="::") first -= 2; // if this is a template collect complete class name if(se[first] == ">") { while(first != 0 && se[first] != "<") --first; // find < --first; // find class name } if(first < 0 || se.length() <= last) return "error in display::functionName"; // ok, now collect std::string temp; for(size_t i=first; i<=last; ++i) temp += se[i] + " "; return temp; } // ///////////////////////////////////////////////////////////////////// // test stub // ///////////////////////////////////////////////////////////////////// #ifdef TEST_DISPLAY #include #include #include "grammar.h" int main(int argc, char* argv[]) { if(argc==1) { cout << "\n please enter name of file to process on command line\n\n"; return 1; } ifstream in(argv[1]); if(!in.good()) { cout << "\n can't read file " << argv[1] << "\n\n"; return 1; } semiExp se(in); while(se.get()) { se.display(); if(grammar(se).include()) cout << " is an include statement" << "\n\n"; else if(grammar(se).functionDef()) cout << " is a function definition" << "\n\n"; } } #endif