void stat(){ if (lookahead == INTEGER || lookahead == STRING || lookahead == BOOLEAN || lookahead == TABLE) def_stat(); else if (lookahead == ID) assign_stat(); else if (lookahead == IF) if_stat(); else if (lookahead == WHILE) while_stat(); else if (lookahead == READ) read_stat(); else //(lookahead == WRITE) write_stat(); }
/*Genera il codice per il nodo stat_list e crea lo scope del programma*/ Code stat_list(Pnode stat_list_node){ //Definisco la variabile che contiene il codice da ritornare Code stat_list_code; stat_list_code.head = NULL; stat_list_code.tail = NULL; stat_list_code.size = 0; //Creo l'ambiente del programma push_environment(); //Punto al primo stat Pnode stat_node = stat_list_node->child; //Ciclo lungo tutti gli stat_node while (stat_node!=NULL){ //Creo il codice dello stat_node Code stat_code; switch (stat_node->type){ case(N_DEF_STAT): stat_code = def_stat(stat_node);break; case(N_ASSIGN_STAT): stat_code = assign_stat(stat_node);break; case(N_IF_STAT): stat_code = if_stat(stat_node);break; case(N_WHILE_STAT): stat_code = while_stat(stat_node);break; case(N_READ_STAT): stat_code = read_stat(stat_node);break; case(N_WRITE_STAT): stat_code = write_stat(stat_node);break; } //Appendo il codice a stat_list_code stat_list_code = appcode(stat_list_code,stat_code); //Punto al fratello successivo stat_node = stat_node->brother; } //Appendo il codice per fare il pop dell'environment a stat_list_code if(numobj_in_current_env()!=0) stat_list_code = appcode(stat_list_code,makecode1(T_POP,numobj_in_current_env())); //elimino l'ambiente creato (elimina già le variabili dall'ambiente) pop_environment(); return stat_list_code; }
Code stat(Pnode p) { switch (p->type) { case N_DEF_STAT: return def_stat(p); case N_ASSIGN_STAT: return assign_stat(p); case N_IF_STAT: return if_stat(p); case N_WHILE_STAT: return while_stat(p); case N_READ_STAT: return read_stat(p); case N_WRITE_STAT: return write_stat(p); default: noderror(p); } return endcode(); }