Beispiel #1
0
/**********************************************
 * Lists the node names in ascending sequence *
 **********************************************/
void listnodes(Node *pNode)
{
  if(pNode->pLeft)
    listnodes(pNode->pLeft);

  for(int i = 0; i<pNode->count ; i++)
    printname(pNode->pName);

  if(pNode->pRight)
    listnodes(pNode->pRight);
}
/* List the node values in ascending sequence */
void listnodes(struct Node *pNode)
{
  if(pNode->pLeft != NULL)
    listnodes(pNode->pLeft);

  for(int i = 0; i<pNode->count ; i++)
    printf("\n%10ld", pNode->item);

  if(pNode->pRight != NULL)
    listnodes(pNode->pRight);
}
Beispiel #3
0
/*============================================
			      主函数
 ============================================*/
int main(void)
{
	long newvalue = 0;
	struct Node *pRoot = NULL;
	char answer = 'n';

	do
	{
		printf("Enter the node value:");
		scanf(" %ld",&newvalue);

		if(pRoot == NULL)
		{
			pRoot = createnode(newvalue);
		}
		else
		{
			addnode(newvalue,pRoot);
		}

		printf("\nDo you want to enter another value (Y or N)?");
		scanf(" %c",&answer);
	}while(tolower(answer) == 'y');

	printf("\nThe value in ascending sequence are:\n");
	listnodes(pRoot);
	freenodes(pRoot);


	return 0;
}
Beispiel #4
0
static void cmp(int op, Symbol p, long n, int lab) {
	Type ty = signedint(p->type);

	listnodes(eqtree(op,
			cast(idtree(p), ty),
			cnsttree(ty, n)),
		lab, 0);
}
Beispiel #5
0
void listnodes (struct Node *pNode)
{
        if (pNode->pLeft != NULL)
                listnodes (pNode->pLeft);
        if (pNode->count != 1) {
                struct LinkedList *tmp = NULL;
                tmp = first;
                while (tmp != NULL) {
                        if (tmp->string_lenth == pNode->string_lenth)
                                printf ("%s", tmp->string);
                        tmp = tmp->pnext;
                }
        }
        printf ("%s", pNode->item);
        if (pNode->pRight != NULL)
                listnodes (pNode->pRight);
}
Beispiel #6
0
/*==========================================
			遍历二叉树并输出
 ==========================================*/
void listnodes(struct Node *pNode)
{
	if(pNode->pleft != NULL)               //好好想想为什么
	{printf("\n1\n");
		listnodes(pNode->pleft);
	}

	for(int i = 0; i<pNode->count; i++)
	{printf("\n2\n");
		printf("%10ld\n",pNode->item);
	}

	if(pNode->pright != NULL)
	{printf("\n3\n");
		listnodes(pNode->pright);
	}
}
Beispiel #7
0
int main (void)
{
        int tmpstring_lenth;
        struct Node *pRoot = NULL;
        bool needfree = false;
        printf ("Type some sentences:\n");

        while (true) {
                tmpstring_lenth = 0;
                char tmpstring[MAX_LEN] = {0};
                fgets (tmpstring, MAX_LEN, stdin);
                if (tmpstring[0] == '\n')
                        break;
                tmpstring_lenth = static_cast<int>(strlen (tmpstring));
                if (pRoot == NULL) {
                        pRoot = createnode (tmpstring, tmpstring_lenth);
                } else {
                        if (addnode (tmpstring, pRoot, tmpstring_lenth) == NULL)
                        {
                                needfree = true;
                                static struct LinkedList *current = NULL;
                                static struct LinkedList *previous = NULL;
                                current = reinterpret_cast<LinkedList *>
                                          (malloc (sizeof (LinkedList)));
                                if (first == NULL)
                                        first = current;
                                if (previous != NULL)
                                        previous->pnext = current;
                                current->string_lenth = tmpstring_lenth;
                                for (int i = 0; i < tmpstring_lenth; ++i) {
                                        current->string[i] = tmpstring[i];
                                }
                                current->pnext = NULL;
                                previous = current;
                        }
                }
                fflush (stdin);
        }
        printf ("All the sentences are:\n");
        listnodes (pRoot);
        freenodes (pRoot);
        if (needfree)
                freelinked (first);
        return 0;
}
Beispiel #8
0
static void asmstmt(int lab, Swtch swp, int lev) { //wjr jan 31 43 lines
        char *asmi, *ireg, *oreg, *symn;
        Tree p;

        t = gettok();
        expect('(');
        definept(NULL);

        if (t != SCON) {
                error("expecting string constant\n");
                return;
        }
        asmi = strdup(tsym->u.c.v.p);
        /*t = gettok();
        expect(':');
        if (t != SCON) {
                error("expecting string constant\n");
                return;
        }
        ireg = strdup(tsym->u.c.v.p);
        t = gettok();
        expect(':');
        if (t != SCON) {
                error("expecting string constant\n");
                return;
        }
        oreg = strdup(tsym->u.c.v.p);*/
        t = gettok();
        expect(')');
        expect(';');

        symn = (char *) malloc(strlen(asmi) /*+ strlen(ireg) + strlen(oreg)*/ +4);
        sprintf(symn, "%s", asmi);// was sprintf(symn, "%s:%s:%s", asmi, ireg, oreg);

        free(asmi);
      /*  free(ireg);
        free(oreg);*/

        p = tree(mkop(IASM, voidtype), voidtype, NULL, NULL);
        p->u.v.p = symn;

        listnodes(p, 0, 0);
}
Beispiel #9
0
void definept(Coordinate *p) {
	Code cp = code(Defpoint);

	cp->u.point.src = p ? *p : src;
	cp->u.point.point = npoints;
	if (ncalled > 0) {
		int n = findcount(cp->u.point.src.file,
			cp->u.point.src.x, cp->u.point.src.y);
		if (n > 0)
			refinc = (float)n/ncalled;
	}
	if (glevel > 2)	locus(identifiers, &cp->u.point.src);
	if (events.points && reachable(Gen))
		{
			Tree e = NULL;
			apply(events.points, &cp->u.point.src, &e);
			if (e)
				listnodes(e, 0, 0);
		}
}
Beispiel #10
0
// Function main - execution starts here
int main(void)
{
  Node *pRoot = NULL;
  char answer = 'n';
  do
  {
    if(!pRoot)
       pRoot = createnode(readname());
    else
      addnode(readname(), pRoot);
    printf_s("\nDo you want to enter another (y or n)? ");
    scanf_s(" %c", &answer, sizeof(answer));
    fflush(stdin);                                    // Get rid of the newline
  } while(tolower(answer) == 'y');

  printf_s("The names in ascending sequence are:\n");
  listnodes(pRoot);                                   // Output the contents of the tree
  freenodes(pRoot);                                   // Release the heap memory

  return 0;
}
Beispiel #11
0
/* Function main - execution starts here */
int main(void)
{
  Name *pNewName = NULL;
  Node *pRoot = NULL;
  char answer = 'n';
  do
  {
    pNewName = readname();
    if(!pRoot)
      pRoot = createnode(pNewName);
    else
    addnode(pNewName, pRoot);
    printf("\nDo you want to enter another (y or n)? ");
    scanf(" %c", &answer);
    fflush(stdin);                    /* Get rid of the newline */
  } while(tolower(answer) == 'y');

  printf("The names in ascending sequence are:\n");
  listnodes(pRoot);          /* Output the contents of the tree */
  freenodes(pRoot);          /* Release the heap memory         */

  return 0;
}
/* Function main - execution starts here */
int main(void)
{
  long newvalue = 0;
  struct Node *pRoot = NULL;
  char answer = 'n';
  do
  {
    printf("Enter the node value: ");
    scanf(" %ld", &newvalue);
    if(pRoot == NULL)
      pRoot = createnode(newvalue);
    else
    addnode(newvalue, pRoot);
    printf("\nDo you want to enter another (y or n)? ");
    scanf(" %c", &answer);
  } while(tolower(answer) == 'y');

  printf("The values in ascending sequence are: ");
  listnodes(pRoot);          /* Output the contents of the tree */
  freenodes(pRoot);          /* Release the heap memory         */

  return 0;
}
Beispiel #13
0
void statement(int loop, Swtch swp, int lev) {
	float ref = refinc;

	if (Aflag >= 2 && lev == 15)
		warning("more than 15 levels of nested statements\n");
	switch (t) {
	case IF:       ifstmt(genlabel(2), loop, swp, lev + 1);
 break;
	case WHILE:    whilestmt(genlabel(3), swp, lev + 1); break;
	case DO:       dostmt(genlabel(3), swp, lev + 1); expect(';');
					break;

	case FOR:      forstmt(genlabel(4), swp, lev + 1);
 break;
	case BREAK:    walk(NULL, 0, 0);
		       definept(NULL);
		       if (swp && swp->lab > loop)
		       	branch(swp->lab + 1);
		       else if (loop)
		       	branch(loop + 2);
		       else
		       	error("illegal break statement\n");
		       t = gettok(); expect(';');
					   break;

	case CONTINUE: walk(NULL, 0, 0);
		       definept(NULL);
		       if (loop)
		       	branch(loop + 1);
		       else
		       	error("illegal continue statement\n");
		       t = gettok(); expect(';');
					      break;

	case SWITCH:   swstmt(loop, genlabel(2), lev + 1);
 break;
	case CASE:     {
		       	int lab = genlabel(1);
		       	if (swp == NULL)
		       		error("illegal case label\n");
		       	definelab(lab);
		       	while (t == CASE) {
		       		static char stop[] = { IF, ID, 0 };
		       		Tree p;
		       		t = gettok();
		       		p = constexpr(0);
		       		if (generic(p->op) == CNST && isint(p->type)) {
		       			if (swp) {
		       				needconst++;
		       				p = cast(p, swp->sym->type);
		       				if (p->type->op == UNSIGNED)
		       					p->u.v.i = extend(p->u.v.u, p->type);
		       				needconst--;
		       				caselabel(swp, p->u.v.i, lab);
		       			}
		       		} else
		       			error("case label must be a constant integer expression\n");

		       		test(':', stop);
		       	}
		       	statement(loop, swp, lev);
		       } break;
	case DEFAULT:  if (swp == NULL)
		       	error("illegal default label\n");
		       else if (swp->deflab)
		       	error("extra default label\n");
		       else {
		       	swp->deflab = findlabel(swp->lab);
		       	definelab(swp->deflab->u.l.label);
		       }
		       t = gettok();
		       expect(':');
		       statement(loop, swp, lev); break;
	case RETURN:   {
		       	Type rty = freturn(cfunc->type);
		       	t = gettok();
		       	definept(NULL);
		       	if (t != ';')
		       		if (rty == voidtype) {
		       			error("extraneous return value\n");
		       			expr(0);
		       			retcode(NULL);
		       		} else
		       			retcode(expr(0));
		       	else {
		       		if (rty != voidtype)
		       			warning("missing return value\n");
		       		retcode(NULL);
		       	}
		       	branch(cfunc->u.f.label);
		       } expect(';');
					    break;

	case '{':      compound(loop, swp, lev + 1); break;
	case ';':      definept(NULL); t = gettok(); break;
	case GOTO:     walk(NULL, 0, 0);
		       definept(NULL);
		       t = gettok();
		       if (t == ID) {
		       	Symbol p = lookup(token, stmtlabs);
		       	if (p == NULL) {
				p = install(token, &stmtlabs, 0, FUNC);
				p->scope = LABELS;
				p->u.l.label = genlabel(1);
				p->src = src;
			}
		       	use(p, src);
		       	branch(p->u.l.label);
		       	t = gettok();
		       } else
		       	error("missing label in goto\n"); expect(';');
					  break;

	case ID:       if (getchr() == ':') {
		       	stmtlabel();
		       	statement(loop, swp, lev);
		       	break;
		       }
	default:       definept(NULL);
		       if (kind[t] != ID) {
		       	error("unrecognized statement\n");
		       	t = gettok();
		       } else {
		       	Tree e = expr0(0);
		       	listnodes(e, 0, 0);
		       	if (nodecount == 0 || nodecount > 200)
		       		walk(NULL, 0, 0);
		       	else if (glevel) walk(NULL, 0, 0);
		       	deallocate(STMT);
		       } expect(';');
						break;

	}
	if (kind[t] != IF && kind[t] != ID
	&& t != '}' && t != EOI) {
		static char stop[] = { IF, ID, '}', 0 };
		error("illegal statement termination\n");
		skipto(0, stop);
	}
	refinc = ref;
}