Пример #1
0
// a function to print the tree 
void printTree2( rootNodePtr r, nodePtr c, double * splitPointLower, double * splitPointUpper ) {

  size_t i;
  double upper_temp;
  double lower_temp;

  if( !c->left  & !c->right) {
    PRINTF("node: %d\n", (int) r->nodeIndex[c->index[0]] );
    if( c->index != NULL) 
      for( i=0; i < r->K; i++) PRINTF("%d: %f, %f\n",(int) i , splitPointLower[i], splitPointUpper[i]); 
    PRINTF("\n");
    return;
  }

  if( c->left ) {
    upper_temp = splitPointUpper[c->dim];

    splitPointUpper[c->dim] = c->split;
    printTree2( r, c->left, splitPointLower, splitPointUpper);

    splitPointUpper[c->dim] = upper_temp;
  }
  
  if( c->right ) {
    lower_temp = splitPointLower[c->dim];

    splitPointLower[c->dim] = c->split;
    printTree2( r, c->right, splitPointLower, splitPointUpper);
    
    splitPointLower[c->dim] = lower_temp;
  }
  
  return;
}
Пример #2
0
void ParseTree::printTree2(Node* node) {
    const char* node_str[] = { "ROOT", "PROG", "DECLS", "DECL", "ARRAY", "STATEMENTS", "STATEMENT", "EXP",
            "EXP2", "INDEX", "OP_EXP", "OP", "INTEGER", "IDENTIFIER", "KEYWORD", "SEMICOLON", "EMPTY" };
    const char* ttype_str[] = { "NO_TYPE", "INTEGER", "IDENTIFIER", "PRINT",
        "READ", "IF", "ELSE", "WHILE", "INT", "ADDITITON", "SUBTRACTION",
        "DIVISION", "MULTIPLICATION", "LT", "GT", "ASSIGN", "NE",
        "EXCLAMATION", "AMPERSAND", "SEMICOLON", "COLON", "LEFTBRACKET",
        "RIGHTBRACKET", "LEFTANGLEBRACKET", "RIGHTANGLEBRACKET",
        "LEFTSQUAREBRACKET", "RIGHTSQUAREBRACKET" };
    const char* type_str[] = { "INTTYPE", "INTARRAYTYPE", "ARRAYTYPE", "NOTYPE", "ERRORTYPE",
                        "OPPLUS", "OPMINUS", "OPMULT", "OPDIV", "OPLESS", "OPGREATER",
                        "OPEQUAL", "OPUNEQUAL", "OPAND" };


    for (int i = 0; i < depth; i++) {
        cout << "  ";
    }
    depth++;

    cout << node_str[node->getRule()];
    if (node->getRule() == ParseEnums::IDENTIFIER) {
        cout << " - Lexem: " << node->getToken()->getEntry()->getLexem();
    } else if (node->getRule() == ParseEnums::INTEGER) {
        cout << " - Wert: " << node->getToken()->getValue();
    } else if (node->getRule() == ParseEnums::KEYWORD) {
        cout << " - Art: " << ttype_str[node->getToken()->getType()];
    }
    cout << " Type: " << type_str[node->getType()];
    cout << endl;
    for (int i = 0; i < node->getChildNodesCount(); i++) {
        printTree2(node->getChildNode(i));
    }

    depth--;
}