示例#1
0
void printexpr(TOKEN tok, int col)     /* print an expression in prefix form */
  { TOKEN opnds; int nextcol, start, i;
    if (PRINTEXPRDEBUG != 0)
      { printf ("printexpr: col %d\n", col);
        dbugprinttok(tok);
      };
    if (tok->tokentype == OPERATOR)
      { printf ("(%s", opprint[tok->whichval]);
        nextcol = col + 2 + opsize[tok->whichval];
        opnds = tok->operands;
	start = 0;
	while (opnds != NULL)
	  { if (start == 0) 
	       printf(" ");
	       else { printf("\n");
		      for (i = 0; i < nextcol; i++) printf(" ");
		    }
	    printexpr(opnds, nextcol);
	    if ( opnds->tokentype == IDENTIFIERTOK && nextcol < 60 )
	       nextcol = nextcol + 1 + strlength(opnds->stringval);
	       else start = 1;
	    opnds = opnds->link;
	  }
        printf (")");
      }
      else printtok(tok);
  }
示例#2
0
void printtree( token *tok ) {
    if( !tok ) {
        return;
    }
    printtok(tok);
    if( tok->lhs ) {
        printf(" (");
        printtree(tok->lhs);
        printf(")");
    }
    if( tok->rhs ) {
        printf(" (");
        printtree(tok->rhs);
        printf(")");
    }
    if( tok->next ) {
        printf(", ");
        printtree(tok->next);
    }
}