Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void symbolTableOrder(){
- // struct list_SymbolTable* cur_table = head_table;
- struct list_SymbolEle* cur_ele = NULL;
- struct list_SymbolTable *top_table_cmp = head_table;
- struct list_SymbolTable *cmp_table = top_table_cmp->next;
- int debugging = 0;
- printf("\nORDERING SYMBOL TABLE...");
- while(top_table_cmp->next != NULL && top_table_cmp != NULL){ // could be while top_table_cmp != NULL
- cmp_table = top_table_cmp->next; //
- cur_ele = top_table_cmp->tableLine_start;
- printf("\nTop table being compared: ");
- while(cur_ele->table_letter != ' '){
- printf("%c",cur_ele->table_letter);
- cur_ele = cur_ele->next;
- }
- while(cmp_table != NULL){ // could be while cmp_table != NULL
- char top_str[top_table_cmp->label_size + 1]; // 1 for '\0'
- cur_ele = top_table_cmp->tableLine_start;
- int count = 0;
- printf("\ntop_str[i] being compared: "); // .. LoopCount
- while(cur_ele->table_letter != ' '){
- // printf("%c",cur_ele->table_letter);
- top_str[count] = cur_ele->table_letter;
- // printf("%i ",count);
- printf("%c",top_str[count]);
- count++;
- cur_ele = cur_ele->next;
- }
- top_str[count] = '\0';
- printf("%c",top_str[count]);
- char cmp_str[cmp_table->label_size + 1]; // 1 for '\0'
- cur_ele = cmp_table->tableLine_start;
- count = 0;
- printf("\nCompare string: "); // .. Count
- while(cur_ele->table_letter != ' '){
- if((cmp_str[count] == '\0') || (cmp_str[count] == '\r') || (cmp_str[count] == '\e') || (cmp_str[count] == '\f'))
- printf("\0");
- cmp_str[count] = cur_ele->table_letter;
- printf("%c", cmp_str[count]);
- count++;
- cur_ele = cur_ele->next;
- }
- cmp_str[count] = '\0';
- printf("%c", cmp_str[count]);
- printf("\nCmp_table->next label: ");
- if(cmp_table->next != NULL){
- cur_ele = cmp_table->next->tableLine_start;
- while(cur_ele->table_letter != ' '){
- printf("%c", cur_ele->table_letter);
- cmp_str[count] = cur_ele->table_letter;
- count++;
- cur_ele = cur_ele->next;
- }
- }
- printf("\nstrcmp(top_str,cmp_str): %i",strcmp(top_str, cmp_str));
- if(strcmp(top_str, cmp_str) > 0){
- bool head_reset = false;
- bool last_reset = false;
- printf("\nTOP COMPARE SWITCHED");
- struct list_SymbolTable *tmp1_table = (struct list_SymbolTable*) malloc(sizeof(struct list_SymbolTable));
- // tmp1_table = top_table_cmp;
- tmp1_table->tableLine_start = top_table_cmp->tableLine_start;
- tmp1_table->label_size = top_table_cmp->label_size;
- tmp1_table->line_number = top_table_cmp->line_number;
- printf("\n\n COPYING NEXT AND PREVIOUS POINTERS..");
- printf("\ntmp1 label: ");
- cur_ele = tmp1_table->tableLine_start;
- while(cur_ele->table_letter != ' '){
- printf("%c", cur_ele->table_letter);
- cmp_str[count] = cur_ele->table_letter;
- count++;
- cur_ele = cur_ele->next;
- }
- tmp1_table->next = cmp_table->next;
- printf("\ntmp1->next label: ");
- cur_ele = tmp1_table->next->tableLine_start;
- while(cur_ele->table_letter != ' '){
- printf("%c", cur_ele->table_letter);
- cur_ele = cur_ele->next;
- }
- printf("\ncmp->next label: ");
- cur_ele = cmp_table->next->tableLine_start;
- while(cur_ele->table_letter != ' '){
- printf("%c", cur_ele->table_letter);
- cur_ele = cur_ele->next;
- }
- tmp1_table->prev = cmp_table->prev;
- printf("\ntmp1->prev label: ");
- cur_ele = tmp1_table->prev->tableLine_start;
- while(cur_ele->table_letter != ' '){
- printf("%c", cur_ele->table_letter);
- cur_ele = cur_ele->next;
- }
- printf("\ncmp->prev label: ");
- cur_ele = cmp_table->prev->tableLine_start;
- while(cur_ele->table_letter != ' '){
- printf("%c", cur_ele->table_letter);
- cur_ele = cur_ele->next;
- }
- cmp_table->next = top_table_cmp->next;
- printf("\ntop_table->next label: ");
- cur_ele = top_table_cmp->next->tableLine_start;
- while(cur_ele->table_letter != ' '){
- printf("%c", cur_ele->table_letter);
- cur_ele = cur_ele->next;
- }
- printf("\n new cmp_table->next label: ");
- cur_ele = cmp_table->next->tableLine_start;
- while(cur_ele->table_letter != ' '){
- printf("%c", cur_ele->table_letter);
- cur_ele = cur_ele->next;
- }
- cmp_table->prev = top_table_cmp->prev;
- // cmp table next and previous = top_cmp_table's next and previous
- printf("\t made it here too.");
- printf(" x");
- if(cmp_table != last_table)
- tmp1_table->next->prev = cmp_table->next->prev;
- else
- last_reset = true; // reset last table BOOL
- printf(" xx");
- if(top_table_cmp != head_table)
- cmp_table->prev->next = top_table_cmp->prev->next;
- else
- head_reset = true; // reset head table BOOL
- printf(" xxx");
- //printf("\n%i");
- tmp1_table->prev->next = tmp1_table;//cmp_table->prev->next;
- printf("\t guess things got messed up over here.");
- top_table_cmp = cmp_table;
- cmp_table = tmp1_table;
- if(head_reset)
- head_table = top_table_cmp;
- else if(last_reset)
- last_table = cmp_table;
- }
- cmp_table = cmp_table->next; // iterate thru symbol table
- } // while cmp_table != NULL
- debugging++;
- printf("\nFinished %i round(s) of sorting",debugging);
- // table_size--; // figured out which one is going to be the top_table_cmp;
- top_table_cmp = top_table_cmp->next; // right now, says top_table_cmp->next === previous cmp_table->next
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement