identifier_list eval_boolean(abstractSyntaxTree temp, symbol_table_ptr st,int scope) { char temp_name[10]; char name[10]; identifier_list id1; identifier_list id2; identifier_list id3; if(temp->symbol == TK_NUM || temp->symbol == TK_RNUM ) { //printf("Current expr is: %s\n",temp->value); sprintf(name , "%d", num_no); strcpy(temp_name,"num"); strcat(temp_name,name); id3 = create_identifier(3,temp->value,temp_name,scope); num_no ++; return (id3); } else if(temp->symbol == TK_ID) { //printf("HI\n"); return (get_symtable_ptr(" ",temp->value, st, scope)); } else if(temp->symbol == TK_NOT) { id1 = eval_boolean(temp->child[0],st,scope); sprintf(name , "%d", temp_no); strcpy(temp_name,"temp"); strcat(temp_name,name); id3 = create_identifier(id1->id_type," ",temp_name,scope); create_quadruple(temp->symbol,id1,NULL,id3); temp_no++; return (id3); } else { id1 = eval_boolean(temp->child[0],st,scope); //printf("Why\n"); id2 = eval_boolean(temp->child[1],st,scope); sprintf(name , "%d", temp_no); strcpy(temp_name,"temp"); strcat(temp_name,name); id3 = create_identifier(id1->id_type," ",temp_name,scope); create_quadruple(temp->symbol,id1,id2,id3); temp_no++; return(id3); } }
void ofold(oast_t *ast) { switch (ast->token) { case tok_com: case tok_plus: case tok_neg: case tok_not: case tok_integer_p: case tok_rational_p: case tok_float_p: case tok_real_p: case tok_complex_p: case tok_number_p: case tok_finite_p: case tok_inf_p: case tok_nan_p: case tok_num: case tok_den: case tok_real: case tok_imag: case tok_signbit: case tok_abs: case tok_signum: case tok_rational: case tok_arg: case tok_conj: case tok_floor: case tok_trunc: case tok_round: case tok_ceil: case tok_sqrt: case tok_cbrt: case tok_sin: case tok_cos: case tok_tan: case tok_asin: case tok_acos: case tok_atan: case tok_sinh: case tok_cosh: case tok_tanh: case tok_asinh: case tok_acosh: case tok_atanh: case tok_proj: case tok_exp: case tok_log: case tok_log2: case tok_log10: eval_unary(ast); break; case tok_andand: case tok_oror: eval_boolean(ast); break; case tok_ne: case tok_lt: case tok_le: case tok_eq: case tok_ge: case tok_gt: case tok_and: case tok_or: case tok_xor: case tok_mul2: case tok_div2: case tok_shl: case tok_shr: case tok_add: case tok_sub: case tok_mul: case tok_div: case tok_trunc2: case tok_rem: case tok_complex: case tok_atan2: case tok_pow: case tok_hypot: eval_binary(ast); break; default: #if DEBUG oparse_warn(ast, "fold: not handling %s", otoken_to_charp(ast->token)); #endif break; } }
void extract_stmt(abstractSyntaxTree temp,symbol_table_ptr st, int scope ) { identifier_list id; char name[10]; char temp_name[10]; //printf("Stmt is : %s\n" ,tokenName[temp->symbol]); if(temp->symbol == TK_ASSIGNOP) { //print_tree(temp); //printf("Sup\n"); //printf("%d\n",temp->childnum); if(temp->child[0]->child[0]->symbol == TK_EPSILON) { //print_tree(temp->child[1]); //printf("Child1 : %s\n",tokenName[temp->child[1]->symbol]); //printf("Searching for %s\n",temp->child[0]->value); id = get_symtable_ptr(" ",temp->child[0]->value, st, scope); //printf("Sym value : %s\n",id->id_name); //printf("HI\n"); create_quadruple(temp->symbol,eval_arithmetic(temp->child[1],st,scope),NULL,id); } else { //printf("Searching for %s.%s\n",temp->child[0]->value ,temp->child[0]->child[0]->value); id = get_symtable_ptr(temp->child[0]->value,temp->child[0]->child[0]->value, st, scope); //printf("Sym table value : %s.%s",id->record_name,id->id_name); create_quadruple(temp->symbol,eval_arithmetic(temp->child[1],st,scope),NULL,id); } } //printf("Hi\n");*/ if(temp->symbol == TK_READ) { if(temp->child[0]->child[0]->symbol == TK_EPSILON) { id = get_symtable_ptr(" ",temp->child[0]->value, st, scope); //printf("Sym value : %s\n",id->id_name); create_quadruple(temp->symbol,id,NULL,NULL); } else { //printf("The record is : %s\n",temp->child[0]->value); //printf("The id is : %s\n",temp->child[0]->child[0]->value); id = get_symtable_ptr(temp->child[0]->value,temp->child[0]->child[0]->value, st, scope); //printf("Sym table value : %s",id->record_name); create_quadruple(temp->symbol,id,NULL,NULL); } } else if(temp->symbol == TK_WRITE) { if(temp->child[0]->symbol == TK_NUM || temp->child[0]->symbol == TK_RNUM ) { //printf("Current expr is: %s\n",temp->value); sprintf(name , "%d", num_no); strcpy(temp_name,"num"); strcat(temp_name,name); id = create_identifier(3,temp->child[0]->value,temp_name,scope); num_no ++; create_quadruple(temp->symbol,id,NULL,NULL); } else if(temp->child[0]->child[0]->symbol == TK_EPSILON) { id = get_symtable_ptr(" ",temp->child[0]->value, st, scope); //printf("Sym value : %s\n",id->id_name); create_quadruple(temp->symbol,id,NULL,NULL); } else { //printf("The record is : %s\n",temp->child[0]->value); //printf("The id is : %s\n",temp->child[0]->child[0]->value); id = get_symtable_ptr(temp->child[0]->value,temp->child[0]->child[0]->value, st, scope); //printf("Sym table value : %s",id->record_name); create_quadruple(temp->symbol,id,NULL,NULL); } } else if(temp->symbol == TK_IF) { int jump1,jump2; //print_tree(temp->child[0]); id = eval_boolean(temp->child[0],st,scope); jump1 = quad_size; create_quadruple(temp->symbol,id,NULL,NULL); extract_stmt(temp->child[1],st,scope); extract_individual_stmts(temp->child[2],st,scope); if(temp->child[3]->symbol == TK_ENDIF) { sprintf(name , "%d", quad_size); quad[jump1].result = create_copy(quad[jump1].result,create_identifier(0," ",name,scope)); } else if(temp->child[3]->symbol == TK_ELSE) { jump2 = quad_size; extract_stmt(temp->child[3]->child[0],st,scope); extract_individual_stmts(temp->child[3]->child[1],st,scope); sprintf(name , "%d", quad_size); quad[jump1].result = create_copy(quad[jump1].result,create_identifier(0," ",name,scope)); sprintf(name , "%d", jump2); quad[jump1].arg2 = create_copy(quad[jump1].arg2,create_identifier(0," ",name,scope)); } } else if(temp->symbol == TK_WHILE) { int jump; create_quadruple(21,NULL,NULL,NULL); id = eval_boolean(temp->child[0],st,scope); create_quadruple(temp->symbol,id,NULL,NULL); jump = quad_size-1; extract_stmt(temp->child[1],st,scope); extract_individual_stmts(temp->child[2],st,scope); sprintf(name , "%d", quad_size); quad[jump].result = create_copy(quad[jump].result,create_identifier(0," ",name,scope)); } //printf("Bye"); }