// file: JSGFParser.h // // make sure definitions are only made once // #ifndef ISIP_JSGF_PARSER #define ISIP_JSGF_PARSER // isip include files // #ifndef ISIP_VECTOR #include #endif #ifndef ISIP_PAIR #include #endif #ifndef ISIP_QUEUE #include #endif #ifndef ISIP_STACK #include #endif #ifndef ISIP_DI_GRAPH #include #endif #ifndef ISIP_JSGF_TOKEN #include #endif // JSGFParser: a class used to parse a JSGF grammar and then convert it to // a directed graph (DiGraph format) which is the ISIP internal grammar // representation // class JSGFParser { //------------------------------------------------------------- // // public constants // //------------------------------------------------------------- public: //define the class name // static const String CLASS_NAME; // constants: i/o related constants // static const String DEF_GRAPH_START; static const String DEF_GRAPH_TERM; static const String DEF_GRAMMAR_NAME; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = (int32)50100; //------------------------------------------------------------- // // protected data // //------------------------------------------------------------- public: // string to store the whole source JSGF grammar // String expression_d; // array of queues to contain all tokens of the expressions // Vector token_vect_d; // index to keep track of the position of the current token // in the above token vector // int32 token_index_d; // a flag to check if grouping parentheses are paired correctly in a rule // correct if the flag is zero after the check // int32 grouping_match_d; // a flag to check if optional grouping brackets are paired correctly // in a rule. correct if the flag is zero after the check // int32 op_grouping_match_d; // a table to store all public rule definitions by pairing // rulenames and their corrsponding rule expansions // Vector > > public_rule_table_d; // a table to store all private rule definitions by pairing // rulenames and their corrsponding rule expansions // Vector > > private_rule_table_d; // a table to store all recursive grammar by pairing // rulenames and their corrsponding terminal tokens // Vector > > recursive_grammar_d; // a table to store vertex index for each graph arc // Vector > arc_index_d; // a vector to store all rulenames that has been processed // since starting running the replaceRuleReference method // It is used to check out unique terminal symbols // Vector processed_rules_d; // token queue for final processing in graph drawing section // Queue final_d; // graph to contain the converted JSGF grammar // DiGraph graph_d; // grammar name // String grammar_name_d; // a list of all terminal symbols in the graph // Vector symbol_list_d; // a list of GraphVertex in the graph // GraphVertex* vertex_list_d[500]; // index of vertex in the graph // int32 vertex_list_index_d; // ISIP default starting and terminial points for DiGraph // String graph_start_d; String graph_term_d; // static memory manager // static MemoryManager mgr_d; //------------------------------------------------------------------------ // // required public methods // //----------------------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // methopd: diagnose // static bool8 diagnose(Integral::DEBUG level_a); // methopd: debug // bool8 debug(const unichar* msg_a) const; // method: destructor // ~JSGFParser() {}; // method: constructor // JSGFParser(); // method: assign // bool8 assign(const JSGFParser& arg_a); // method: operator= // JSGFParser& operator=(const JSGFParser& arg_a) { assign(arg_a); return *this; } // equality methods // bool8 eq(const JSGFParser& arg_a) const; // method: read // bool8 read(Sof& sof, int32 tag, const String& cname = CLASS_NAME) { return Error::handle(name(), L"read", Error::NOT_IMPLEM, __FILE__, __LINE__); } // method: write // bool8 write(Sof& sof, int32 tag, const String& cname = CLASS_NAME) const { return Error::handle(name(), L"write", Error::NOT_IMPLEM, __FILE__, __LINE__); } // method: clear // bool8 clear(Integral::CMODE ctype_a); // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static bool8 setGrowSize(int32 grow_size) { return mgr_d.setGrow(grow_size); } //------------------------------------------------------------- // // class-specified public methods // //------------------------------------------------------------- public: // method: setExpression // bool8 setExpression(String& expression_a); // method: parserJSGF // bool8 parseJSGF(const String& graph_start_a, const String& graph_term_a); // method: parserJSGF // bool8 parseJSGF(){ return parseJSGF(L"", L""); } // method: getGraph // DiGraph getGraph() { return graph_d; } // method: getSymbolList // Vector getSymbolList() { return symbol_list_d; } // method: getGrammarName // String getGrammarName() { return grammar_name_d; } // method: getPublicRuleNames // bool8 getPublicRuleNames(Vector& public_tokens_a); // method: getPublicRuleNames // bool8 getPublicRuleNames(Vector& public_tokens_a); // method: getTokenVector // Vector getTokenVector() { return token_vect_d; } //------------------------------------------------------------- // // private methods // //------------------------------------------------------------- private: // method: getToken // bool8 getToken(); // method: parseGrammar // bool8 parseGrammar(); // method: parseRuleDefinition // bool8 parseRuleDefinition(); // method: parseRuleExpansion // bool8 parseRuleExpansion(); // method: parseUnit // bool8 parseUnit(); // method: parseGrouping // bool8 parseGrouping(); // method: parseOptionalGrouping // bool8 parseOptionalGrouping(); // method: setRuleTables // bool8 setRuleTables(); // method: ruleNotDefined // bool8 ruleNotDefined(JSGFToken& rulename_a); // method: replaceRuleExpansion // bool8 replaceRuleReference(JSGFToken& rulename_a, Stack& replaced_rules_a); // method: replaceRecursionRuleExpansion // bool8 replaceRecursionRuleReference(String& rulename_a, Stack replaced_rules_a, Queue& rule_final_a); // method: resolveReference // bool8 resolveReference(String& rulename_a, Vector& rule_exp_a); // method: setVertexIndex // bool8 setVertexIndex(JSGFToken& token_a); // method: drawGraph // bool8 drawGraph(); // method: drawUnit // bool8 drawUnit(Vector& start_a, Vector& end_a, bool8 is_alter_a); // method: searchStartEnd // bool8 searchStartEnd(Vector& start_a, Vector& end_a, bool8 is_alter, Queue& rule_final_a); // method: findArcIndex // bool8 findArcIndex(int32 first_index_a, int32 second_index_a); }; // end of include file // #endif