⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maple.cc

📁 this is a lp0 compilator new
💻 CC
字号:
//// *********************************************************************// *// *	Author     	: Gerald Carter// *                   	  cartegw@humsci.auburn.edu// *   	Filename      	: maple.cc// *   	Date Created  	: 960110// * // * 	Description : This is the C++ class definition for a // *		syntaxNode class.  This class will be used to // *		build a maple expression tree.// *// *	----------------------// *	Modofications// *	----------------------// *// *********************************************************************//// HEADER FILES#include <iostream.h>#include <stdlib.h>#include "maple.h"#include "labels.h"//*********************************************************************void mapleNode::PrintTreeLabels (ostream& S){   char			label_string[100];   if (SizeOfFamily() == 0)       S << "Leaf node : " << label2string ( GetLabel(), label_string ) << endl;   else {      syntaxNode          **children = 0;      children = GetChildren ();      for (int i = 0; i < SizeOfFamily(); ++i)	 (*(children+i))->PrintTreeLabels ( S );      S << "Interior node : " << label2string ( GetLabel(), label_string )        << "......" << SizeOfFamily() << endl;   }   return;};         // end of mapleNode::PrintTreeLabels ()      //*********************************************************************void mapleNode::PrintTree ( ostream& S ){   // Print the outer 'rsolve' command and rely on EvaluateExpressionTree   // to fill in between the '(' & ')'s.   EvaluateExpressionTree ( S , 1 );   return;};      // end of mapleNode::PrintTree ()//*********************************************************************int mapleNode::EvaluateExpressionTree ( ostream& S, int beginning ){   // local variables   int 			hold_flag;   int 		 	constant = 0;   syntaxNode	 	**children = 0;   syntaxNode*		tmp_ptr = 0;   int			j = 0;   char			indent[256] = "";   // Keep a tally of the additional constant value to add    // to the recurrence equation.   if ( value != 0 )      if ( beginning )      {         beginning = 0;         S << "1";      }      else         S << "+1";   switch ( GetLabel() )   {      case CONSTANT_VALUE :          if ( beginning )            beginning = 0;         else            S << "+";         S << "1";         break;         case FOR_STATEMENT :         children = GetChildren ();         // Initial condition maple expression         beginning = ( * ( (mapleNode**)children ) )->EvaluateExpressionTree ( S , beginning );         // Concluding condition maple expression         beginning = ( * ( (mapleNode**)children + 1 ) )->EvaluateExpressionTree ( S, beginning );         if ( beginning )            beginning = 0;         else            S << "+";         S << "sum (";         hold_flag = beginning;         beginning = 1;         // Maple expression for body of the loop         beginning = ( * ( (mapleNode**)children + 2 ) )->EvaluateExpressionTree ( S, beginning );         beginning = hold_flag;         S << ", ";         tmp_ptr = GetSyntaxTree ( 0 );         tmp_ptr->PrintTree ( S, indent, j );         S << "=";         tmp_ptr = GetSyntaxTree ( 1 );         tmp_ptr->PrintTree ( S, indent, j );         S << "..";         tmp_ptr = GetSyntaxTree ( 2 );         tmp_ptr->PrintTree ( S, indent, j );         S << ")";         break;      case PROCEDURE_CALL :      case FUNCTION_CALL :         if ( beginning )            beginning = 0;         else            S << "+";         S << expr_string;          break;                         default :         children = GetChildren ();         for ( int i=0; i<SizeOfFamily(); i++ )            // must cast children to (mapleNode**) because children are from            // base class syntaxNode.  However each tree is homogeneous so this            // is safe.            beginning = ( * ( (mapleNode**)children + i ) )->EvaluateExpressionTree ( S, beginning );         break;   }   // successful completion   return ( beginning );};      // end of mapleNode::EvaluateExpressionTree ()//********** end of maple.cc ******************************************//*********************************************************************

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -