///////////////////////////////////////////////////////////////////// // Prototype.cpp - Demonstrate grammar processing // // // // Language: Visual C++ 2008 // // Platform: Dell Dimension 9200, Windows Vista Ultimate // // Application: Prototype for CSE687 Pr1, Sp08 // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////////// #include "..\Scanner\SemiExpression.h" #include "Prototype.h" //----< is this a control token preceding a paren? >----------------- bool Prototype::isSpecialControlKey(const std::string& tok) { const int NUMKEYS = 5; static std::string KeyTable[NUMKEYS] = { "if", "for", "while", "switch", "catch" }; for(int i=0; i------ int Prototype::findFunctions() { if(pToker_ == 0) throw std::exception("no registered toker"); pToker_->returnComments(); SemiExp se(pToker_); se.makeCommentSemiExp(); // process file while(se.getSemiExp()) { if(se.find("{") == se.length()) continue; int posParen = se.find("("); if(posParen == se.length()) continue; if(posParen == 0 || isSpecialControlKey(se[posParen-1])) continue; if(isVerbose_) { std::cout << " at line #" << pToker_->lines() + 1 << ": " << se.showSemiExp().c_str() << std::endl; } Item item = { se[posParen-1], pToker_->lines() + 1 }; functions.push_back(item); } return functions.size(); } //----< Demonstrate results of ad hoc grammar processing >----------- int main(int argc, char* argv[]) { std::cout << "\n Simple Grammar Demonstration\n " << std::string(23,'=') << std::endl; if(argc < 2) { std::cout << "\n please enter name of file to process on command line\n\n"; return 1; } for(int i=1; i functions = pr.getFunctions(); std::cout << '\n'; std::cout << " Final results of analysis\n"; std::cout << " ---------------------------\n"; for(std::vector::size_type i=0; i