///////////////////////////////////////////////////////////////// // simpleGrammar.cpp - C++ grammar detectors // // ver 1.1 // // Language: Visual C++, ver 7.1 // // Platform: Dell Dimension 8300, Windows XP Prof, SP 2 // // Application: CSE687 prototype for project #1, Spring 2005 // // Author: Jim Fawcett, CST 2-187, Syracuse University // // (315) 443-3948, jfawcett@twcny.rr.com // ///////////////////////////////////////////////////////////////// #include "simpleGrammar.h" //----< constructor with initializer sequence >------------------ SimpleGrammar::SimpleGrammar(const SimpleSemiExp &se) : se_(se) {} //----< is this a class declaration? >--------------------------- bool SimpleGrammar::isClass() const { if(se_.find("class") < se_.length()) return true; } //----< is special key word? >----------------------------------- // // private global helper function - not declared in header // bool isSpecialKey(const std::string &tok) { std::string key[5] = { "for", "if", "while", "switch", "catch" }; for(int i=0; i<5; ++i) if(tok.compare(key[i]) == 0) return true; return false; } //-----< is this a function definition? >------------------------ bool SimpleGrammar::isFunctionDef() const { if(se_.last().compare("{")==0) { unsigned int pos = se_.find("("); if(pos < se_.length()) if(!isSpecialKey(se_[pos-1])) return true; } return false; } //----< is this an object declaration? >------------------------- bool SimpleGrammar::isObjectDecl() const { return false; } // //----< test stub >---------------------------------------------- #ifdef TEST_SIMPLEGRAMMAR #include int main(int argc, char *argv[]) { if(argc < 2) { std::cout << "\n please enter name of file to process\n\n"; return 1; } std::ifstream in; for(int i=1; i