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

📄 gen_maple.cc

📁 this is a lp0 compilator new
💻 CC
📖 第 1 页 / 共 3 页
字号:
int FactorLabel ( int& maple_label, int& num_children, syntaxNode* tree ){   // What we do depends actually on the child label   switch ( tree -> GetChildLabel () )   {      // We must look at the variable complexity expression due      // to array references and nested variable ( ie pointers,      // records, etc... )      case VARIABLE_LABEL :         maple_label = VARIABLE_;         num_children = 1;         break;      // These cases are done in constant time      case UNSIGNED_LIT_LABEL :      case SET_RULE_LABEL :         maple_label = CONSTANT_VALUE;         num_children = 0;         break;      // We will deal with function calls later      case FUNCTION_CALL_LABEL :      {         syntaxNode		**children = 0;	 syntaxNode		*ident_root = 0;         char			*symbol_name;         // initialize         children = tree -> GetChildren ();         ident_root = *(children+0);         // we must traverse down the tree ( although we know	 // it is straight down due to the grammar...away we go ).         while ( ident_root -> SizeOfFamily() != 0 ) {            children = ident_root -> GetChildren ();            ident_root = *(children+0);         }         // at this point ident_root should be pointing to the          // node holding the lexeme for the procedure / function         symbol_name = strdup ( (ident_root -> GetLexeme ()) -> GetSymbolName () );         procStack.Push ( symbol_name );	 maple_label = FUNCTION_CALL;         num_children = 0;      }       break;      // The time is the time complexity of the child expression      case EXPRESSION_LABEL :         maple_label = EXPRESSION;         num_children = 1;         break;      // The time is the time complexity of the simplified factor      case NOT_FACTOR_LABEL :         maple_label = FACTOR;         num_children = 1;         break;      // There is an error in the label assignment      default :         cerr << "Bad FACTOR_LABEL child label." << endl;         break;   }     // successful completion   return (0);}// ********************************************************************// *// *    VariableLabel ()// *// *    Description :   This function sets the mapleNode labels and number// *                    of children for the mapleExpressionTree based// *                    on the values in the occurrence of a VARIABLE_LABEL// *                    syntaxNode label// *int VariableLabel ( int& maple_label, int& num_children, syntaxNode* tree ){   // What we do depends actually on the child label   switch ( tree -> GetChildLabel () )   {      // Constant time complexity      case IDENT_LABEL :         maple_label = CONSTANT_VALUE;         num_children = 0;         break;      // Complexity := Compx(var) + Compx(expression)      // See pas.y ( grammar )      case ARRAY_LABEL :         maple_label = ARRAY_;         num_children = 2;         break;      // Complexity := Compx(var)       // See pas.y ( grammar )      case RECORD_LABEL :         maple_label = RECORD_;         num_children = 1;         break;      // Complexity := Compx(var)      // See pas.y ( grammar )      case POINTER_LABEL :         maple_label = POINTER_;         num_children = 1;         break;      // There is an error in the label assignment      default :         cerr << "Bad VARIABLE_LABEL child label." << endl;         break;   }   // successful completion   return ( 0 );}// ********************************************************************// *// *	TermLabel ()// *	// *	Description :	This function sets the mapleNode labels and number// *			of children for the mapleExpressionTree based// *			on the values in the occurrence of a TERM_LABEL// *                    syntaxNode label// *int TermLabel ( int& maple_label, int& num_children, syntaxNode* tree ){   // What we do depends actually on the child label   switch ( tree -> GetChildLabel () )   {      // The time is the time complexirt of the factor rule      case FACTOR_LABEL :         maple_label = FACTOR;         num_children = 1;         break;        // The time is the time complexity of the (term + factor)      case MULTI_OP_LABEL :         maple_label = TERM_PLUS_FACTOR;         num_children = 2;         break;      // There is an error in the label assignment      default :         cerr << "Bad FACTOR_LABEL child label." << endl;         break;   }     // successful completion   return (0);}// ********************************************************************// *// *	SimpleExprLabel ()// *	// *	Description :	This function sets the mapleNode labels and number// *			of children for the mapleExpressionTree based// *			on the values in the occurrence of a SIMPLE_EXPR_LABEL// *                    syntaxNode label// *int SimpleExprLabel ( int& maple_label, int& num_children, syntaxNode* tree ){   // What we do depends actually on the child label   switch ( tree -> GetChildLabel () )   {      // The time is the time complexity of the term      case TERM_LABEL :      case UNARY_MINUS_LABEL :      case UNARY_PLUS_LABEL :         maple_label = TERM;         num_children = 1;         break;      // The time is the time complexity of the ( simple_expr + term )      case ADD_OP_LABEL :         maple_label = SIMPLE_EXPR_PLUS_TERM;         num_children = 2;         break;      // There is an error in the label assignment      default :         cerr << "Bad SIMPLE_EXPR_LABEL child label." << endl;         break;   }     // successful completion   return (0);}// ********************************************************************// *// *	ExpressionLabel ()// *	// *	Description :	This function sets the mapleNode labels and number// *			of children for the mapleExpressionTree based// *			on the values in the occurrence of a EXPRESSION_LABEL// *                    syntaxNode label// *int ExpressionLabel ( int& maple_label, int& num_children, syntaxNode* tree ){   // What we do depends actually on the child label   switch ( tree -> GetChildLabel () )   {      // The time is the time complexity of the simple_expr      case SIMPLE_EXPR_LABEL :         maple_label = SIMPLE_EXPR;         num_children = 1;         break;      // The time is the time complexity of ( simple_expr + simple_expr )      case RELATIONAL_OP_LABEL :         maple_label = SIMPLE_EXPR_PLUS_SIMPLE_EXPR;         num_children = 2;         break;      // There is an error in the label assignment      default :         cerr << "Bad EXPRESSION_LABEL child label." << endl;         break;   }     // successful completion   return (0);}// ********************************************************************// *// *    ExpressionsLabel ()// *// *    Description :   This function sets the mapleNode labels and number// *                    of children for the mapleExpressionTree based// *                    on the values in the occurrence of a EXPRESSIONS_LABEL// *                    syntaxNode label// *int ExpressionsLabel ( int& maple_label, int& num_children, syntaxNode* tree ){   // What we do depends actually on the child label   switch ( tree -> GetChildLabel () )   {      // The time is the time complexity of the simple_expr      case SEQUENTIAL_EXPR_LABEL :         maple_label = SEQUENTIAL_EXPR;         num_children = 2;         break;      // The time is the time complexity of ( simple_expr + simple_expr )      case EXPRESSION_LABEL :         maple_label = EXPRESSION;         num_children = 1;         break;      // There is an error in the label assignment      default :         cerr << "Bad EXPRESSIONS_LABEL child label." << endl;         break;   }   // successful completion   return (0);}// ********************************************************************// *// *	AssignmentLabel ()// *	// *	Description :	This function sets the mapleNode labels and number// *			of children for the mapleExpressionTree based// *			on the values in the occurrence of a ASSIGNMENT_LABEL// *                    syntaxNode label// *int AssignmentLabel ( int& maple_label, int& num_children, syntaxNode* tree ){   // The time is the time complexity of left-hand-side + right-hand-side   maple_label = EXPRESSION;   num_children = 2;   // successful completion   return ( 0 );}// ********************************************************************// *// *	StatementLabel ()// *	// *	Description :	This function sets the mapleNode labels and number// *			of children for the mapleExpressionTree based// *			on the values in the occurrence of a STATEMENT_LABEL// *                    syntaxNode label// *int StatementLabel ( int& maple_label, int& num_children, syntaxNode* tree ){   // What we do depends actually on the child label   switch ( tree -> GetChildLabel () )   {      // Do nothing      case GOTO_LABEL :          maple_label = 0;         num_children = -1;         break;      // The time is the time complexity of the replacing statement      case STATEMENT_LABEL :      case COMPOUND_STMT_LABEL :      case ASSIGNMENT_LABEL :         maple_label = UNIT_STATEMENT;         num_children = 1;         break;      // The Empty Statement is for syntax not complexity      case EMPTY_STATEMENT :         maple_label = tree -> GetChildLabel ();         num_children = 0;         break;         // The time is the time complexity of the procedure / function call      case PROCEDURE_CALL_LABEL :      {         syntaxNode		**children = 0;	 syntaxNode		*ident_root = 0;         char			*symbol_name;         // initialize         children = tree -> GetChildren ();         ident_root = *(children+0);         // we must traverse down the tree ( although we know	 // it is straight down due to the grammar...away we go ).         while ( ident_root -> SizeOfFamily() != 0 ) {            children = ident_root -> GetChildren ();            ident_root = *(children+0);         }         // at this point ident_root should be pointing to the          // node holding the lexeme for the procedure / function         symbol_name = strdup ( (ident_root -> GetLexeme ()) -> GetSymbolName () );         procStack.Push ( symbol_name );	 maple_label = PROCEDURE_CALL;         num_children = 0;      }       break;      // The time is the summation of the time complexity of the body       // of the loop over the loop index range      case FOR_LABEL :         maple_label = FOR_STATEMENT;         num_children = 3;         break;            // We will come back to these cases later      case IF_LABEL :         maple_label = IF_STATEMENT;         num_children = 2;         break;      case IF_ELSE_LABEL :         maple_label = IF_ELSE_STATEMENT;         num_children = 2;         break;       case CASE_LABEL :         maple_label = 0;         num_children = -1;         break;       case WHILE_LABEL :         maple_label = WHILE_STATEMENT;         num_children = -1;         push_node = FALSE;         break;       case REPEAT_LABEL :         maple_label = REPEAT_STATEMENT;         num_children = -1;         push_node = FALSE;         break;      // There is an error in the label assignment      default :         cerr << "Bad STATEMENT_LABEL child label..." << tree -> GetChildLabel ()              << endl;         break;   }     // successful completion   return (0);}// ********************************************************************// *// *	StatementsLabel ()// *	// *	Description :	This function sets the mapleNode labels and number// *			of children for the mapleExpressionTree based// *			on the values in the occurrence of a STATEMENTS_LABEL// *                    syntaxNode label// *int StatementsLabel ( int& maple_label, int& num_children, syntaxNode* tree ){   // What we do depends actually on the child label   switch ( tree -> GetChildLabel () )

⌨️ 快捷键说明

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