📄 symbol.h
字号:
//// ******************************************************************// * // * Author : Gerald Carter// * cartegw@humsci.auburn.edu// * Filename : symbol.h// * File created : 940107// *// * This file contains the class declaration for a binary// * search tree. The tree may only be searched, inserted in to and// * printed useing the "put to" (ie. '<<') operator. It constructs// * the tree using nodes of type symbolNode that hold the data and the// * left/right child pointers.// *// * ---------------------// * Modifications// * ---------------------// * 961206 cartegw@humsci.auburn.edu// * added field to symbolNode to hold the maple function // * name as well a pointer to the function maple expression // * tree.// *// ********************************************************************//// Test for previous inclusion#ifndef _SYMBOL_H#define _SYMBOL_H// Class declaration tagclass symbolNode;class symbolTable;// INCLUDE FILES#include <iostream.h> // overload << operator#include "logic.h" // boolean typedef#include "maple.h" // mapleNode class// #####################################################################// ## Macros for existence field in symbolNode// ###define ITS_A_UNDEFINED 0#define ITS_A_FUNCTION 1#define ITS_A_VARIABLE 2#define ITS_A_PROGRAM 3#define ITS_A_PROCEDURE 4#define ITS_A_CONSTANT 5 #define ITS_A_EXTERNAL_FILE 6#define ITS_A_TYPE 7#define ITS_A_ENUM_LITERAL 8#define ITS_A_FIELD 9#define ITS_A_DONT_KNOW 10#define ITS_A_VALUE_PARAM 11#define ITS_A_VAR_PARAM 12#define ITS_A_PROCEDURE_PARAM 13#define ITS_A_FUNCTION_PARAM 14#define ITS_A_CONFORMANT_BOUND 15// #####################################################################// ## class symbolNode// ## class symbolNode { private : char *name; // symbol name int its_a; // function, variable, program, etc... char *maple_name; // maple experssion name mapleNode *maple_expr; // maple expression tree for function // Method to generate maple_name char* nextMapleFunction ( char[] ); public : // CONSTRUCTORS symbolNode (void) { name = 0; its_a = ITS_A_UNDEFINED; maple_name = 0; maple_expr = 0; }; symbolNode (char*); symbolNode (const symbolNode&); // DESTRUCTOR ~symbolNode (void) { delete name; delete maple_name; }; // TYPE CASTING... operator char* (void) const { return name; } // OVERLOADED OPERATORS symbolNode& operator= (const symbolNode&); int operator< (const symbolNode&); int operator> (const symbolNode&); int operator== (const symbolNode&); int operator!= (const symbolNode&); friend ostream& operator<< (ostream&, const symbolNode&); // GENERAL METHODS char* GetSymbolName ( void ) const { return ( name ); }; int SetExistence (const int ); int GetExistence (void) { return its_a; }; char* GetMapleName ( void ) const { return ( maple_name ); }; mapleNode* GetMapleExpression ( void ) { return ( maple_expr ); }; mapleNode* SetMapleExpression ( mapleNode* m) { maple_expr = m; };}; // end of class symbolNode// #####################################################################// ## class symbolTable// ## class symbolTable { private : struct node { // node in tree symbolNode data; node *left_child, *right_child; }; node *root; // root of tree int RecursivePrint // recursive solutin to the operator<< (); (ostream& outS, struct node* current_node) const; int DeleteTree // recursive destructor (struct node *current_node); void ProcExpression ( ostream&, node* ); public: symbolTable (void) { root = 0; } ~symbolTable (void) { DeleteTree (this->root); } symbolNode* Search (const symbolNode&); // is node there? symbolNode* Insert (const symbolNode&); // put node in tree friend ostream& operator<< (ostream& S, const symbolTable& tree) { tree.RecursivePrint (S, tree.root); return S; } void PrintProcExpr ( ostream& S ) // Perform a search of the table { ProcExpression ( S, root ); } // and print maple expressions // of all functions / procedures}; // end of class symbolTable#endif//******** end of symbol.h ********************************************//*********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -