Ejemplo n.º 1
0
char*
pretty_print_any(TreeNode* node, int dd)
{
    int64_t vv_i;
    double  vv_d;

    switch (node->type) {
    case INTEGER_TYPE:
        vv_i = *((int64_t*)node->data);
        return lsprintf("%ld", vv_i);
    case FLOAT_TYPE:
        vv_d = *((double*)node->data);
        return lsprintf("%f", vv_d);
    case SYMBOL_TYPE:
        return (char*)node->data;
    case STRING_TYPE:
        return pretty_print_string(node, dd);
    case BINOP_TYPE:
        return pretty_print_binop(node, dd);
    case UNOP_TYPE:
        return pretty_print_unop(node, dd);
    case DOT_TYPE:
        return pretty_print_dot(node, dd);
    case BIND_TYPE:
        return pretty_print_bind(node, dd);
    case LIST_TYPE:
        return pretty_print_list(node, dd);
    case FUN_TYPE:
        return pretty_print_fun(node, dd);
    case LAMBDA_TYPE:
        return pretty_print_lambda(node, dd);
    case CALL_TYPE:
        return pretty_print_call(node, dd);
    case CALL_LAMBDA_TYPE:
        return pretty_print_call_lambda(node, dd);
    default:
        carp("pretty_print_tree(): Bad node type.");
    }

    abort();
}
Ejemplo n.º 2
0
void pretty_print(lexeme tree) {

	if (tree == NULL) {
		//fprintf(stderr, "Got empty tree. Returning...\n");
		return;
	}
	
	lexeme_type type = lexeme_get_type(tree);
	switch(type) {
		case PAIR:
			pretty_print_pair(tree);
			break;
		case STRING:
			pretty_print_string(tree);
			break;
		case AMP:
			pretty_print_amp(tree);
			break;
		case DOT:
			pretty_print_dot(tree);
			break;
		case RETURN:
			pretty_print_return(tree);
			break;
		case BLOCK:
			pretty_print_block(tree);
			break;
		case UNITLIST:
			pretty_print_unitlist(tree);
			break;
		case INT:
			pretty_print_int(tree);
			break;
		case DEC:
			pretty_print_dec(tree);
			break;
		case TRUE:
			pretty_print_true(tree);
			break;
		case FALSE:
			pretty_print_false(tree);
			break;
		case NIL:
			pretty_print_nil(tree);
			break;
		case ID:
			pretty_print_id(tree);
			break;
		case BIND:
			pretty_print_bind(tree);
			break;
		case LAMBDA:
			pretty_print_lambda(tree);
			break;
		case PARAMLIST:
			pretty_print_paramlist(tree);
			break;
		case CALL:
			pretty_print_call(tree);
			break;
		case ARGLIST:
			pretty_print_arglist(tree);
			break;
		default:
			printf("BAD LEXEME");
			lexeme_destroy(tree);
			break;
	}
}