#ifndef GRAMMAR_H #define GRAMMAR_H ///////////////////////////////////////////////////////////////////// // grammar.h - provides detectors for grammatical constructs // // ver 1.5 // // // // 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 // ///////////////////////////////////////////////////////////////////// /* Module Operation: ================= The grammar module provides a set of detector functions that identify gramatical constructs captured by the tokens in a CSemiExp object. Public Interface: ================= CSemiExp se(in); // create a CSemiExp object grammar g(se); // create a grammar object bool b = g.functionDef(); // is a function definition? bool b = g.include(); // is an include statement? */ ///////////////////////////////////////////////////////////////////// // Build Process // ///////////////////////////////////////////////////////////////////// // Required Files: // // grammar.h, grammar.cpp, CppSemiExp.h, CppSemiExp.cpp, // // CppToker.h, CppToker.cpp // // // // Compiler command: // // cl /DTEST_GRAMMAR grammar.cpp display.cpp\ // // CppSemiExp.cpp CppToker.cpp // ///////////////////////////////////////////////////////////////////// /* Maintenance History: ==================== ver 1.6 : 08 Feb 05 - fixed a bug in classDef() that improperly handles a semi-expression with a single "{", an unusual case, by changing the type of index from unsigned to int. This was reported by Mingdong Shang. Thanks MingDong. ver 1.5 : 22 Jan 04 - modified test stub. ver 1.4 : 10 Mar 04 - strengthened include detector to work even if "#" is not the first token in semi-expression. ver 1.3 : 09 Mar 04 - fixed bug reported by Siddharth Mulchandani. The include detector did not check to ensure the semi-expression length was greater than one before checking se[0] and se[1]. - also added a length check for functionDef detector. - Digant Mehta reported a problem with scanner that turned out to be caused by leading newlines in semi-expressions collected by scanner in scanner::process. I added se.stripLeadingNewLines() in grammar's constructor to eliminate this problem. ver 1.2 : 29 Feb 04 - added calls to CToker::setDefaultFilters() and CSemiExp::setDefaultFilters() in Grammar test stub - strengthened function definition grammar to prevent a rare false alarm ver 1.1 : 08 Feb 04 - several small changes to accomodate using CppSemiExp and CppToker modules instead of Semi and Tok. ver 1.0 : 08 Feb 03 - first release */ // #include "CppSemiExp.h" namespace Scanner { class grammar { public: grammar(CSemiExp &se); bool include(); bool classDef(); bool functionDef(); bool invocation(); bool declar(); private: bool specialKeys(const std::string &s); CSemiExp& _se; // don't copy }; //----< initializes a grammar object with a semiExp >---------- inline grammar::grammar(CSemiExp &se) : _se(se) { se.stripLeadingNewLines(); } } #endif