diff options
| -rw-r--r-- | tree.c | 116 | 
1 files changed, 38 insertions, 78 deletions
| @@ -86,12 +86,40 @@ ptree *list;  void set_ret_type(t)  ptree *t;  { -	if (!t){ +	if (!t)  		return; -	} - -	switch (t->type) { + +	set_ret_type(t->l); +	set_ret_type(t->r); +	t->ret_type = check_ret_type(t); + +	return; +} + + +/*PRINT FUNCS*/ + +void print_tree(t) +ptree *t; +{ +	fprintf(stderr, "\n\nTREE\n" +	"==========================================================\n"); +	aux_tree_print(t, 0); +	fprintf(stderr, +	"**********************************************************\n"); +	return; +} + +void aux_tree_print(t, spaces) +ptree* t; +int spaces; +{ +	int i; +	if ( t ) { +		for (i = 0; i < spaces; i++) +			fprintf(stderr," "); +		switch (t->type) {  		case ADDOP:  			fprintf(stderr, "[ADDOP]");  			break; @@ -131,80 +159,12 @@ ptree *t;  		case ASSIGNOP:  			fprintf(stderr, "[ASSIGN]");  			break; -		default: -			fprintf(stderr, "\t%d", t->type); -			yyerror("Error in tree_print"); -	} -	set_ret_type(t->l); -	set_ret_type(t->r); -	t->ret_type = check_ret_type(t); - -	return; -} - - -/*PRINT FUNCS*/ - -void print_tree(t) -ptree *t; -{ -	fprintf(stderr, "\n\nTREE\n" -	"==========================================================\n"); -	aux_tree_print(t, 0); -	fprintf(stderr, -	"**********************************************************\n"); -	return; -} - -void aux_tree_print(t, spaces) -ptree* t; -int spaces; -{ -	int i; -	if ( t ) { -		for (i = 0; i < spaces; i++) -			fprintf(stderr," "); -		switch (t->type) { -		 -			case ADDOP: -				fprintf(stderr, "[ADDOP]"); -				break; -			case MULOP: -				fprintf(stderr, "[MULOP]"); -				break; -			case RELOP: -				fprintf(stderr, "[RELOP]"); -				break; -			case NOT: -				fprintf(stderr, "[NOT]"); -				break; -			case ARRAY_ACCESS: -				fprintf(stderr, "[ARRAY ACCESS]"); -				break; -			case LIST: -				fprintf(stderr, "[LIST]"); -				break; -			case ID: -				if (t->r && t->r->attr.nval) -					fprintf(stderr, "[ID: %s %s]", -						t->r->attr.nval->name, -						pretty_type( -							t->attr.nval->var_type)); -				else -					fprintf(stderr, "[ID: %s %s]", -						t->attr.nval->name, -						pretty_type( -							t->attr.nval->var_type)); -				break; -			case INUM: -				fprintf(stderr, "[INUM: %d]", t->attr.ival); -				break; -			case RNUM: -				fprintf(stderr, "[RNUM: %f]", t->attr.rval); -				break; -			case ASSIGNOP: -				fprintf(stderr, "[ASSIGN]"); -				break; +		case IF: +			fprintf(stderr, "[IF]"); +			break; +		case THEN: +			fprintf(stderr, "[THEN]"); +			break;  			default:  				fprintf(stderr, "\t%d", t->type);  				yyerror("Error in tree_print"); | 
