pnode_t add_word(pnode_t phead) { char word[WORD_LEN]; char explain[EXPLAIN_LEN]; if (get_info(word, explain)) phead = insert_to_file(word, explain, phead); return phead; }
V_NODE *add_word(V_NODE *head) { char w[WORD_LEN]; char ex[EX_LEN]; if(get_info(w, ex) > 0) { // head = add_to_file(w, ex, head);//在后面插入的 head = insert_to_file(w, ex, head);//改进后按字母ascii码大小插入的 } return head; }
void pass1(void){ char line[100]; char orig_line[100]; //SICXE_OP *instPtr; /* Read first input line */ fgets(line, 100, source_file); strcpy(orig_line, line); get_format(line); /* if OPCODE = 'START' then */ if(!strcmp(OPCODE, "START")){ /* Save #[OPERAND] as starting address (Relocation -> start at 0)*/ /* Initialize LOCCTR to starting address */ LOCCTR = 0; // Enable to be Relocation /* Write line to intermedite file */ insert_to_file(orig_line); line_Counter++; /* Read next line */ fgets(line, 100, source_file); strcpy(orig_line, line); get_format(line); } else{ /* Initialize LOCCTR to 0 */ LOCCTR = 0; } /* while OPCODE != 'END' do */ while(strcmp(OPCODE, "END")){ print_type = 1; // Normal PREV_LOCCTR = LOCCTR; /* if this is not a comment line then */ if(1){ /* if there is a symbol in the LABEL field then */ if(SYMBOL_ox == 1){ insert_SYMTAB(SYMBOL); } /* search OPTAB for OPCODE, if found then */ if(search_OPTAB(&instPtr)){ /* add instruction length to LOCCTR */ LOCCTR += (OPCODE_format); } /* else if OPCODE = 'WORD' */ else if(!strcmp(OPCODE, "WORD")){ /* add 3 to LOCCTR */ LOCCTR += 3; } /* else if OPCODE = 'RESW' */ else if(!strcmp(OPCODE, "RESW")){ /* add 3 * #[OPERAND] to LOCCTR */ LOCCTR += (3 * atoi(OPERAND1)); } /* else if OPCODE = 'RESB' */ else if(!strcmp(OPCODE, "RESB")){ /* add #[OPERAND] to LOCCTR */ LOCCTR += atoi(OPERAND1); } /* else if OPCODE = 'BYTE' */ else if(!strcmp(OPCODE, "BYTE")){ /* find length of constant in bytes */ /* add length to LOCCTR */ LOCCTR += (byte_Length()); } /* else if OPCODE = 'BASE' */ else if(!strcmp(OPCODE, "BASE")){ /* find length of constant in bytes */ /* add length to LOCCTR */ print_type = 2; // Directive } /* else */ else{ /* Set EORROR flag (invalid operation code) */ printf("EORROR! %s is Invalid Operation Code.\n", OPCODE); exit(0); } } /* Write line to intermediate file */ insert_to_file(orig_line); /* Read next line */ fgets(line, 100, source_file); strcpy(orig_line, line); get_format(line); line_Counter++; } /* Write last line to intermediate file */ print_type = 2; // Directive insert_to_file(orig_line); /* Save (LOCCTR - starting address) as program length */ program_Length = (LOCCTR - 0); return ; }