///////////////////////////////////////////////////////////////////// // grammar.cpp - provides detectors for grammatical constructs // // ver 1.6 // // // // 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 #include "grammar.h" using namespace Scanner; //----< class declaration? >----------------------------------- bool grammar::classDef() { if(_se.length() == 0) return false; if(_se[_se.length()-1] != std::string("{")) return false; for(int i=0; i<(int)_se.length()-2; ++i) if(_se[i] == "class") return true; return false; } //----< is this string a special key? >------------------------ bool grammar::specialKeys(const std::string &s) { static std::string keys[6] = { "for", "if", "switch", "while", "=", "catch" }; for(int i=0; i<6; ++i) if(s==keys[i]) return true; return false; } //----< beginning of a function definition? >------------------ bool grammar::functionDef() { if(_se.length() == 0) return false; if(_se[_se.length()-1] != std::string("{")) return false; size_t len = _se.find("("); if(len == _se.length()) return false; if(specialKeys(_se[len-1])) return false; if(ispunct(_se[len-1][0])) return false; return true; } //----< detects #include statements >-------------------------- bool grammar::include() { if(_se.length() > 1) { size_t pos = _se.find("#"); if(pos < _se.length()-1 && _se[pos+1] == "include") return true; } return false; } //----< a declaration> >--------------------------------------- bool grammar::declar() { // incomplete definition return false; } // #ifdef TEST_GRAMMAR #include #include int main(int argc, char *argv[]) { std::cout << "\n Testing Prototype Grammar Module " << "\n ==================================\n"; if(argc==1) { std::cout << "\n please enter name of file to process on command line\n\n"; return 1; } for(int i=1; i