📄 syntax.h
字号:
//// ********************************************************************// * syntax.h// * ------------------------------------------------------------ // * Author : Gerald Carter// * cartegw@humsci.auburn.edu// * Filename : syntax.h// * Date Created : 960110// *// * Description : This is the header file for a C++ class// * implementation of a syntax tree.// *// * -------------------------// * Modifications // * -------------------------// * 970219 cartegw@eng.auburn.edu Gerald Carter// * Added the method expression2string in order to convert// * a syntax tree to a character string ( stringcl ).// *// *********************************************************************//// Test for previous inclusion#ifndef _SYNTAX_H#define _SYNTAX_H// ###################################################################// ## Class Declaration Tag// ##class symbolNode; // defined in symbol.hclass syntaxNode;// HEADER FILES#include <iostream.h>#include "labels.h"#include "stringcl.h"typedef struct { int label_id; char* name;} labelEntry;// ####################################################################// ## class syntaxNode// ##class syntaxNode { private : union family_part { syntaxNode **children; symbolNode *lexeme; }; int label; int child_label; int num_children; family_part family; static labelEntry labels[]; // Private member function for class use only (utilities) void PrintChildren (ostream&, char*, int&); void ExpressChildren ( string& ); void OutputGML ( ostream&, int& ); public : // Constructors & Destructor syntaxNode ( void ) { label = child_label = num_children = 0; family.lexeme = 0; } syntaxNode (int new_label) { label = new_label; child_label = num_children = 0; family.lexeme = 0; } ~syntaxNode (void) { delete [](family.children); } // General Access methods int SetLabel (int new_label) { label = new_label; return label; } int GetLabel (void) { return label; } int GetChildLabel (void) { return child_label; } syntaxNode** AdoptChildren (int, int, syntaxNode*[]); syntaxNode** GetChildren (void) { if ( num_children==0 ) return ( 0 ); else return ( family.children ); } int SizeOfFamily (void) { return num_children; } symbolNode *SetLexeme (symbolNode* new_lexeme) { num_children = 0; family.lexeme = new_lexeme; return family.lexeme; } symbolNode *GetLexeme (void) { return (family.lexeme); } // Output method virtual void PrintTree (ostream&, char*, int&); virtual void PrintTreeLabels (ostream&); virtual char* label2string ( int, char[] ); virtual void PrintGML ( ostream& ); virtual string& expression2string ( string& ); // Overloaded Operators syntaxNode& operator= (syntaxNode&);}; // end of class syntaxNode// MORE HEADER FILES#include "symbol.h"#endif//******** end of syntax.h ********************************************//*********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -