// file: JSGFToken.h // // make sure definitions are only made once // #ifndef ISIP_JSGF_TOKEN #define ISIP_JSGF_TOKEN // isip include files // #ifndef ISIP_CHAR #include #endif #ifndef ISIP_STRING #include #endif #ifndef ISIP_FLOAT #include #endif #ifndef ISIP_LONG #include #endif #ifndef ISIP_VECTOR #include #endif // Token: a class to store a tokenized component of JSGF grammar // class JSGFToken { //-------------------------------------------------------- // // public constants // //-------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; // constants: i/o related constants // static const int32 DEF_TOKEN_TYPE; static const String DEF_HEADER; static const String DEF_KEYWORD; static const String DEF_GRAMMAR_NAME; static const String DEF_IMPORT_GRAMMAR; static const String DEF_RULENAME; static const String DEF_TERMINAL; static const String DEF_OPERATOR; static const String DEF_TAG; static const String DEF_TERM_RULE_NAME; static const float32 DEF_WEIGHT; static const int32 DEF_TERM_ROW; static const int32 DEF_TERM_COL; static const int32 DEF_VERTEX_INDEX; static const bool8 DEF_IS_HEAD_GROUP; static const bool8 DEF_WEIGHTED_TERMINAL; static const int32 DEF_OPERATOR_SIZE; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = (int32)50200; //------------------------------------------------------------- // // protected data // //------------------------------------------------------------- public: enum TYPE {HEADER = 0, KEYWORD, GRAMMAR_NAME, IMPORT_GRAMMAR_NAME, RULE_NAME, TERMINAL, TAG, QUOTED_TOKEN, WEIGHT, OPERATOR, MARKER, DEF_TYPE = HEADER}; // numeric value identifying the token's type // 0: header // 1: keyword // 2: grammar name // 3: import grammar name // 4: rule name // 5: terminal // 6: tag // 7: quoted token // 8: weight // 9: operator // 10: parser-defined marker // TYPE token_type_d; // self-identifying header // String header_d; // keyword (public) // String keyword_d; // grammar name // String grammar_name_d; // import grammar // String import_grammar_d; // refernce to a rule in surrounding <> // String rulename_d; // a speakable terminal token // String terminal_d; // operators // Vector operator_d; // tag string surrounded by {} // String tag_d; // weight of the token // float32 weight_d; // term_row: the index of the queue containing this terminal (row) // int32 term_row_d; // term_rule_name: the name of the rule containing this terminal (row) // String term_rule_name_d; // term_col: the index of this terminal in the queue (column) // int32 term_col_d; // vertex_index: the index of this terminal in the symbol vertex list // int32 vertex_index_d; // is_head_group: flag to determine if the token is optional group // bool8 is_head_group_d; // weight flag indicating if a weight is assigned to the token // bool8 weighted_terminal_d; // static memory manager // static MemoryManager mgr_d; //-------------------------------------------------------- // // required public methods // //-------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // method: diagnose // static bool8 diagnose(Integral::DEBUG level_a); // method: debug // bool8 debug(const unichar* msg_a) const; // method: destructor // ~JSGFToken() {}; // method: constructor // JSGFToken(); // method: assign // bool8 assign(const JSGFToken& arg_a); // method: operator= // JSGFToken& operator=(const JSGFToken& arg_a) { assign(arg_a); return *this; } // method: eq // bool8 eq(const JSGFToken& arg_a) const; // method: operator== // bool8 operator==(const JSGFToken& arg_a) { return eq(arg_a); } // 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: 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); } // method: clear // bool8 clear(Integral::CMODE ctype_a = Integral::RELEASE); //-------------------------------------------------------- // // class-specified public methods // //-------------------------------------------------------- public: //-------------------------------------------------------- // // get/set methods // //-------------------------------------------------------- // method: setOperator // // method: get // // method: setHeader // bool8 setHeader(String header_a) { return header_d.assign(header_a); } // method: getHeader // String getHeader() { return header_d; } // method: setKeyword // bool8 setKeyword(String keyword_a) { return keyword_d.assign(keyword_a); } // method: get // String getKeyword() { return keyword_d; } // method: setGrammarName // bool8 setGrammarName(String grammar_name_a) { return grammar_name_d.assign(grammar_name_a); } // method: getGrammarName // String getGrammarName() { return grammar_name_d; } // method: setImportGrammar // bool8 setImportGrammar(String import_grammar_a) { return import_grammar_d.assign(import_grammar_a); } // method: getImportGrammar // String getImportGrammar() { return import_grammar_d; } // method: setRuleName // bool8 setRuleName(String rule_name_a) { return rulename_d.assign(rule_name_a); } // method: getRuleName // String getRuleName() { return rulename_d; } // method: setTag // bool8 setTag(String tag_a) { return tag_d.assign(tag_a); } // method: getTag // String getTag() { return tag_d; } // method: setWeight // bool8 setWeight(float32 weight_a) { weight_d = weight_a; return true; } // method: getWeight // float32 getWeight() { return weight_d; } // method: setToken // bool8 setToken(const String& arg_a); // method: setVertexIndex // bool8 setVertexIndex(const int32 vertex_index_a); // method: setTermRuleName // bool8 setTermRuleName(const String& rule_name_a); // method: setMarker // bool8 setMarker(const String& marker_a, const JSGFToken& name_a); // method: printToken // bool8 printToken(); // method: getTerminal // String getTerminal() { return terminal_d; } // method: set // bool8 setTerminal(String terminal_a) { return terminal_d.assign(terminal_a); } // method: getTokenType // TYPE getTokenType() { return token_type_d; } // method: setTokenType // bool8 setTokenType(TYPE token_type_a) { token_type_d=token_type_a; return true; } // method: setCoordinate // bool8 setCoordinate(int32 row_a, int32 col_a); // method: setTerminalWeight // bool8 setTerminalWeight(JSGFToken& arg_a); //-------------------------------------------------------- // // private methods // //-------------------------------------------------------- private: // method: isHeader // bool8 isHeader(const String& arg_a); // method: isKeyword // bool8 isKeyword(const String& arg_a); // method: isGrammarName // bool8 isGrammarName(const String& arg_a); // method: isImportGrammar // bool8 isImportGrammar(const String& arg_a); // method: isRulename // bool8 isRulename(const String& arg_a); // method: isTerminal // bool8 isTerminal(const String& arg_a); // method: isOperator // bool8 isOperator(const String& arg_a); // method: isTag // bool8 isTag(const String& arg_a); // method: isQuotedToken // bool8 isQuotedToken(const String& arg_a); // method: isWeight // bool8 isWeight(const String& arg_a); }; // end of file // #endif