Example #1
0
int
main(int argc, char **argv) {
	options(argc, argv);

	yyparse();

#ifdef DUMP_TREES
	if ((DUMP_TREES & 1) != 0)
		node_print(stderr, root, 0);
#endif

	simplify_tree(&root, root);

#ifdef DUMP_TREES
	if ((DUMP_TREES & 2) != 0)
		node_print(stderr, root, 0);
#endif

	/* Parsing and semantics are ok, redirect stdout to file (if requested) */
	if (outfile != NULL) {
		if (freopen(outfile, "w", stdout) == NULL) {
			fprintf(stderr, "Could not open output file '%s'\n", outfile);
			exit(EXIT_FAILURE);
		}
		free(outfile);
	}

	destroy_subtree(root);

	exit(EXIT_SUCCESS);
}
Example #2
0
int node_print(struct node *p) {
  if (p == NULL)
    return 0;

  node_print(p->left);
  printf("%d\n", p->data);
  node_print(p->right);
  return 0;
}
Example #3
0
hubbub_error append_child(void *ctx, void *parent, void *child, void **result)
{
    node_t *tparent = parent;
    node_t *tchild = child;

    node_t *insert = NULL;

    tchild->next = tchild->prev = NULL;

#ifndef NDEBUG
    printf("appending (%p):\n", (void *) tchild);
    node_print(NULL, tchild, 0);
    printf("to:\n");
    if (parent != (void *)1)
        node_print(NULL, tparent, 0);
#endif

    *result = child;

    if (parent == (void *)1) {
        if (Document) {
            insert = Document;
        } else {
            Document = tchild;
        }
    } else {
        if (tparent->child == NULL) {
            tparent->child = tchild;
        } else {
            insert = tparent->child;
        }
    }

    if (insert) {
        while (insert->next != NULL) {
            insert = insert->next;
        }

        if (tchild->type == CHARACTER && insert->type == CHARACTER) {
            insert->data.content = realloc(insert->data.content,
                                           strlen(insert->data.content) +
                                           strlen(tchild->data.content) + 1);
            strcat(insert->data.content, tchild->data.content);
            *result = insert;
        } else {
            insert->next = tchild;
            tchild->prev = insert;
        }
    }

    if (*result == child)
        tchild->parent = tparent;

    ref_node(ctx, *result);

    return HUBBUB_OK;
}
Example #4
0
void node_print(struct node *n,int tabs) {
	if(n != NULL) {
		int i;
		node_print(n->right,tabs+1);
		for(i=0; i<tabs; i++) {
			printf("\t");
		}
		printf("%c(%d)\n",n->key,n->priority);
		node_print(n->left,tabs+1);
	}
}
Example #5
0
File: ast.c Project: flowlo/ubvl
void node_print(ast_node *node, int indent) {
	if (node == NULL)
		return;

	printf("%*d %s ", indent, node->op, op_name[node->op]);
	switch (node->op) {
		case O_ID:	printf("%s", node->name);	break;
		case O_NUM:	printf("%ld", node->value);	break;
		case O_VARDEF:	printf("%s", node->name);	break;
	}
	printf("\n");
	node_print(node->left, indent + 8);
	node_print(node->right, indent + 8);
}
Example #6
0
void
node_print ( node_t *root, int nesting )
{   
    if ( root != NULL )
    {
        /* Print the type of node indented by the nesting level */
        printf ( "%*c%s", nesting, ' ', node_string[root->type] );

        /* For identifiers, strings, expressions and numbers,
         * print the data element also
         */
        if ( root->type == IDENTIFIER_DATA ||
             root->type == STRING_DATA ||
             root->type == EXPRESSION ) 
            printf ( "(%s)", (char *) root->data );
        else if ( root->type == NUMBER_DATA ){
            printf ( "(%ld)", *((int64_t *)root->data) );
        }

        /* Make a new line, and traverse the node's children in the same manner */
        putchar ( '\n' );
        for ( int64_t i=0; i < root->n_children; i++ ){
            node_print ( root->children[i], nesting+1 );
        }
    }
    else
        printf ( "%*c%p\n", nesting, ' ', root );
}
Example #7
0
void export_named_dot(const SGraph *the_sgraph, ion *out,
                      suif_vector<String>* name_map) {
    out->printf("digraph foo {\nsize = \"8,10\";\n");

    SNodeIter iter(the_sgraph->get_node_iterator());
    // Print out nodes names and their labels
    for (; !iter.done(); iter.increment()) {
        SGraphNode node = iter.get();
        the_sgraph->print_node(out, node);
        out->printf(" [");
        out->printf("shape=box, label=\"");
        node_print(node, the_sgraph, out, name_map);
        out->printf("\"];\n");
    }

    iter = the_sgraph->get_node_iterator();
    // Print out each connecting edge
    for (; !iter.done(); iter.increment()) {
        SGraphNode from_node = iter.get();
        for (SNodeIter iter2(the_sgraph->get_node_successor_iterator(from_node));
                !iter2.done(); iter2.increment()) {
            SGraphNode to_node = iter2.get();
            the_sgraph->print_node(out, from_node);
            out->printf(" -> ");
            the_sgraph->print_node(out, to_node);
            //out->printf("%s", (*name_map)[to_node].c_str());
            out->printf("\n");
        }
    }
    out->printf("}\n");
}
Example #8
0
//
// AUTOTEST: ann node
//
void xautotest_ann_node()
{
    float w[4] = {1,2,3,4}; // weights vector
    float x[3] = {5,1,3};   // input vector
    float y[1];             // output vector

    // create node
    node q = node_create(w,     // weights
                         x,     // input
                         y,     // output
                         3,     // num_inputs
                         0,     // activation function ID
                         1.0f   // activation function gain
                        );

    // evaluate node
    node_evaluate(q);

    if (liquid_autotest_verbose) {
        node_print(q);
        printf("y = %12.8f\n", y[0]);
    }

    // contend equality of output
    CONTEND_EQUALITY(y[0], 20.0f);

    // destroy node
    node_destroy(q);
}
Example #9
0
File: vslc.c Project: edgarmv/NTNU
int
main ( int argc, char **argv )
{
    yyparse();
    node_print ( root, 0 );
    destroy_subtree ( root );
}
Example #10
0
int
main ( int argc, char **argv )
{
    outputStage = 12;

    options ( argc, argv );

    /* In order to only scan the tokens we call yylex() directly */
    if ( outputStage == 1 ) {
        do { } while ( yylex() ); // "Token files"
        exit(0);
    }

    /* The parser calls yylex(), match the rules and builds the abstract syntax tree */
    // "BuildTree files"
    yyparse();
    if ( outputStage == 2 ) {
        exit(0); // Exit if we are only printing this stages debug information. "BuildTree files"
    }

    /* Print the abstract syntax tree */
    if ( outputStage == 3 ) {
        node_print ( stderr, root, 0 ); // "Tree files"
        exit(0);
    }

    destroy_subtree ( stderr, root );


    yylex_destroy(); // Free internal data structures of the scanner.

    exit ( EXIT_SUCCESS );
}
Example #11
0
void test_array()
{
    START_CODE(node)
	IF
	    IN
                RAW_PARAM(3)
		ARRAY_CONSTANT(array_create(3, 1,2,3));
	    END;
	THEN
	    CATEGORY_CONSTANT(1)
	ELSE
	    CATEGORY_CONSTANT(2)
	END;
    END_CODE;

    node_print(node);

    node = test_serialization(node);

    environment_t env = test_environment();

    constant_t v = node_eval(node, &env);
    assert(v.c == 2);
    assert(v.type == CONSTANT_CATEGORY);

    env.row->inputs[3].category = 3;
    v = node_eval(node, &env);
    assert(v.c == 1);
    assert(v.type == CONSTANT_CATEGORY);

    row_destroy(env.row);
    node_destroy(node);
}
Example #12
0
int main()
{  
	Queue queue = queue_new();

	enqueue(queue, node_new(1));
	printf("1.Simon node is %p\n", queue->rear);
	enqueue(queue, node_new(2));
	printf("1.Filoa node is %p\n", queue->rear);
	enqueue(queue, node_new(3));
	printf("1.Cindy node is %p\n", queue->rear);
	enqueue(queue, node_new(4));
	printf("1.Gateman node is %p\n", queue->rear);
	printf("queue len is %d\n", queue->len);

	printQueue(queue);

	int i = 0;
	LLQNode node;
	printf("5. node is %p\n", node);
	int len = queue->len;
	for(i = 0; i < len; i++)
	{
		printf("2. i is %d\n", i);
		dequeue(queue, &node);
		node_print(node);
		printf("2. %p\n", node);
		printf("\n");
		free(node);
	}
	printf("\n");


	return 0;
}
Example #13
0
//print the key,val pairs of a given row
void node_print_row( Node** head){
  Node* temp = *head;
  while( temp != NULL){
    node_print( temp);
    temp = temp->next;
  }
  fprintf(stdout, "\n");
}
Example #14
0
/* insert 'child' before 'ref_child', under 'parent' */
hubbub_error insert_before(void *ctx, void *parent, void *child,
                           void *ref_child, void **result)
{
    node_t *tparent = parent;
    node_t *tchild = child;
    node_t *tref = ref_child;

#ifndef NDEBUG
    printf("inserting (%p):\n", (void *) tchild);
    node_print(NULL, tchild, 0);
    printf("before:\n");
    node_print(NULL, tref, 0);
    printf("under:\n");
    if (parent != (void *)1)
        node_print(NULL, tparent, 0);
#endif

    if (tchild->type == CHARACTER && tref->prev &&
            tref->prev->type == CHARACTER) {
        node_t *insert = tref->prev;

        insert->data.content = realloc(insert->data.content,
                                       strlen(insert->data.content) +
                                       strlen(tchild->data.content) + 1);
        strcat(insert->data.content, tchild->data.content);

        *result = insert;
    } else {
        tchild->parent = parent;

        tchild->prev = tref->prev;
        tchild->next = tref;
        tref->prev = tchild;

        if (tchild->prev)
            tchild->prev->next = tchild;
        else
            tparent->child = tchild;

        *result = child;
    }

    ref_node(ctx, *result);

    return HUBBUB_OK;
}
int main(int argc, char *argv[]) {
  Node *head;
  node_create(&head, 3);
  node_append(head, 2);
  node_append(head, 4);
  node_append(head, 5);

  printf("BEFORE\n");
  node_print(head);

  node_delete_elem(head->next->next);

  printf("AFTER\n");
  node_print(head);

  return 0;
}
Example #16
0
void heap_print(const Heap* heap, int level, // root is at level 1
                void (*node_print) (const void* node, const void* arg, int level))
{
    if(level < 1) level = 1;
    if(level > heap->size) return;
    heap_print (heap, level*2+1  , node_print);      // right subtree
    node_print (heap->data[level], heap->arg, level);// print heap node
    heap_print (heap, level*2+0  , node_print);      // left subtree
}
Example #17
0
File: list.c Project: karoon/431
int node_print(node n, FILE *stream) {
   int length = 0; 
   if (n) {
      length += variable_byte_encode(n->docno, stream);
      length += variable_byte_encode(n->count, stream);
      length += node_print(n->next, stream);
   }
   return length;
}
Example #18
0
void node_print(node_t *n)
{
	printf("[K:%d C:%c, ", n->key, (n->color == RED) ? ('r') : ((n->color == BLACK) ? ('b') : ('?')));

	if (!is_nil(n->left))
		node_print(n->left);
	else
		printf("nil");

	printf(", ");

	if (!is_nil(n->right))
		node_print(n->right);
	else
		printf("nil");

	printf("]");
}
Example #19
0
int main(int argc, char* argv[]) {
	int i, j, k;
	char c;

	node *head = (node*) malloc(sizeof(node)); // 헤드 노드 생성
	head->next = NULL; // 잘못된 주소 할당 방지 위해 next 포인터 0x0 으로 만들어 놓기 -> head 노드가 노드의 끝이라는 것 명시
	printf("Main: %p, %p\n", head, head->next); // 헤드 노드 및 next 포인터 프린트


	while(1) {
		printf("Input command(I: insert, A: append, C: Append sequentially, D: delete, P: print, R: print all. E: exit.\n");
		scanf(" %c", &c);
		if(c =='E' || c == 'e') break;
		switch(c) {
			case 'I':
			case 'i':
				printf("Input number and position (For example, 4 5 measn put number 4 in fifth node)\n");
				scanf("%d %d", &i, &j);
				node_insert(head, i, j);
				break;
			case 'A' :
			case 'a' :
				printf("Input number (for example, 4 means append number 4)\n");
				scanf("%d", &i);
				node_append(head, i);
				break;
			case 'C' :
			case 'c' :
				printf("Input number (for example, 4 8 means append number 4 5 6 7 8 in a row)\n");
				scanf("%d %d", &i, &j);
				for(k=i; k<=j; k++)
					node_append(head, k);
				break;
			case 'D' :
			case 'd' :
				printf("Input node position to delete (For example, 5 means delete node in postition 5)\n");
				scanf("%d", &i);
				node_remove(head, i);
				break;
			case 'P' :
			case 'p' :
				printf("Input node position to print(For example, 5 means print number in fifth node)\n");
				scanf("%d", &i);
				node_print(head, i);
				break;
			case 'R' :
			case 'r' :
				node_print_all(head);
				break;
		}
	}


	free(head);
	return 0;
}
Example #20
0
void list_print(union list_t list, union node_t* nodes)
{
   printf("list.d64:%016llX head:%08X tail:%08X\n", list.d64, list.s.head, list.s.tail);
   u32 next = list.s.head;
   while(next) {
      union node_t n = nodes[next];
      node_print(n);
      next = n.s.next;
   }
}
Example #21
0
File: c.c Project: cmin764/cmiN
int* node_print(Node node)
{
    static int cnt = 0;
    if (!node->next)
        return &cnt;
    ++cnt;
    printf("(%d, %d) ", node->offset, node->length);
    node_print(node->next);
    return &cnt;
}
Example #22
0
// return 1 if key exists, 0 if not;
int ht_exists( Htable htable, int key, int d){
  int val_expec = ht_mod_hash( htable, key);
  int flag = 0;
  Node* temp = (htable->table)[val_expec];
  while( temp != NULL && !flag){
    if(d) node_print( temp);
    if(temp->key == key)
      flag = 1;
    temp = temp->next;
  }
  return flag == 0 ? 0 : 1;
}
Example #23
0
int
main ( int argc, char **argv )
{
    yyparse();
    node_print ( root, 0 );
    destroy_subtree ( root );
    
    // int token;
    // while ((token = yylex()) != 0)
    //     printf("Token: %d ('%s')\n", token, yytext);
    // printf("\n");
}
Example #24
0
//delete a node in a chaing of nodes
//if a node's val == passed val, delete it and fix the list
void node_delete( Node** head, int key, int val, int d){
  Node* temp = *head;
  if( temp == NULL){
    fprintf( stderr, "ERROR, DELETE FROM EMPTY LIST)");
  }
  else if( temp->val == val){
    if(d) node_print( temp);
    *head = temp->next;
    free( temp);
  }
  else{
    while( temp->next != NULL && temp->next->val != val){
      if(d) node_print( temp);
      temp = temp->next;
    }
    if( temp->next != NULL && temp->next->val == val){
      Node* holder = temp->next;
      temp->next = temp->next->next;
      free( holder);
    }
  }
}
Example #25
0
File: btree.c Project: bigbes/btree
int print_tree(struct DB *db, struct BTreeNode *node) {
	node_print(node);
	if (node->h->flags & IS_LEAF)
		return 0;
	int i = 0;
	for (i = 0; i < node->h->size + 1; ++i) {
		assert(node->chld[i] != 0);
		struct BTreeNode n;
		node_btree_load(db, &n, node->chld[i]);
		print_tree(db, &n);
		node_free(db, &n);
	}
	return 0;
}
Example #26
0
void
node_print (struct node * n, int indent)
{
  if (n->left != NULL)
    node_print (n->left, indent + 1);
  else
    {
      print_indent (indent + 1);
      printf ("nothing\n");
    }

  print_indent (indent);
  printf ("data: %s\n", n->data);


  if (n->right != NULL)
    node_print (n->right, indent + 1);
  else
    {
      print_indent (indent + 1);
      printf ("nothing\n");
    }
}
Example #27
0
void ring_print_all() {
  Node *current = NULL;
  Ring *ring = ring_get();
  int i = 0; 
  
  printf("%-4s %-11s %-5s %-5s %-7s\n", "Key", "ID", "Pred", "Succ", "# Docs");
  printf("---- ----------- ----- ----- -------\n");
  
  for (i = 0; i < ring->size; i++) {
    current = ring->nodes[i];

    node_print(current);
  }
}
Example #28
0
void print_named(const SGraph *the_sgraph, ion *out,
                 suif_vector<String> *name_map)
{
    //    out->printf("digraph foo {\nsize = \"8,10\";\n");
    out->printf("BEGIN GRAPH\n");
    // Print out nodes names and their labels
    {   for (SNodeIter iter(the_sgraph->get_node_iterator());
                !iter.done(); iter.increment()) {
            SGraphNode node = iter.get();
            out->printf(" %d{", node);
            node_print(node, the_sgraph, out, name_map);
            out->printf("}\n");
        }
    }


    // Print out each connecting edge
    {   for (SNodeIter iter = the_sgraph->get_node_iterator();
                !iter.done(); iter.increment()) {
            SGraphNode from_node = iter.get();
            for (SNodeIter iter2(the_sgraph->get_node_successor_iterator(from_node));
                    !iter2.done(); iter2.increment()) {
                SGraphNode to_node = iter2.get();
                out->printf(" %d{", from_node);
                node_print(from_node, the_sgraph, out, name_map);
                out->printf("} ");
                out->printf(" -> ");
                out->printf(" %d{", to_node);
                node_print(to_node, the_sgraph, out, name_map);
                out->printf("} ");
                out->printf("\n");
            }
        }
    }
    out->printf("END GRAPH\n");
}
Example #29
0
File: c.c Project: cmin764/cmiN
int main()
{
    Node node = node_create(NULL, -1, 0);
    int size;
    fputs("Dimensiune: ", stdout);
    scanf("%d", &size);
    do {
        puts("[1] Afiseaza");
        puts("[2] Aloca");
        puts("[3] Elibereaza");
        puts("[4] Defragmenteaza");
        puts("[0] Iesi");
        fputs(">>> ", stdout);
        int ask;
        scanf("%d", &ask);
        if (!ask) {
            node_free(node, NULL);
            break;
        } else if (ask < 1 || ask > 4)
            puts("Optiune invalida");
        else if (ask == 1) {
            int* cnt = node_print(node);
            if (*cnt) {
                *cnt = 0;
                putchar('\n');
            }
        } else if (ask == 2) {
            int length;
            fputs("Lungime: ", stdout);
            scanf("%d", &length);
            int offset = nalloc(&node, length, size);
            if (offset == -1)
                puts("Nu se poate aloca");
            else
                printf("S-a alocat la adresa %d\n", offset);
        } else if (ask == 3) {
            int offset, length;
            fputs("Adresa: ", stdout);
            scanf("%d", &offset);
            fputs("Lungime: ", stdout);
            scanf("%d", &length);
            nfree(&node, offset, length);
        } else if (ask == 4)
            ndefrag(node);
        putchar('\n');
    } while (1);
    return 0;
}
Example #30
0
void node_print(FILE *output, node_t *root, uint32_t nesting) {
	if (root != NULL) {
		fprintf(output, "%*c%s", nesting, ' ', root->type.text);
		if (root->type.index == INTEGER)
			fprintf(output, "(%d)", *((int32_t *)root->data));
		if (root->type.index == VARIABLE || root->type.index == EXPRESSION) {
			if (root->data != NULL)
				fprintf(output, "(\"%s\")", (char *)root->data);
			else
				fprintf(output, "%p", root->data);
		}
		fputc('\n', output);
		for (int32_t i = 0; i < root->n_children; i++)
			node_print(output, root->children[i], nesting + 1);
	} else
		fprintf(output, "%*c%p\n", nesting, ' ', root);
}