#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main () {
char line[4];
char label[7],opcode[7],operand[8];
//char startAddr[5];
int LOCCTR = 0;
char comment[50];
char checkOP[7];
int count = 0;
FILE *input,*inter,*output,*OP;
input = fopen("input.txt","r");
inter = fopen("intermediate.txt","w");
OP = fopen("OPTAB.txt","r");
if(input == NULL){
printf("Can't read input\n");
}
else{
if(fscanf(input,"%s %s %s %s",line,label,opcode,operand)!=EOF){ //處理
第一行的部分
if(!strcmp(opcode,"START")){
fprintf(inter,"%s %04d %s %s %s\n",line,LOCCTR,label,opcode,ope
rand);//將第一階段結果寫入中間檔案
fscanf(input,"%s %s %s %s",line,label,opcode,operand); //讀取下一行
}
else{
printf("failed\n");
}
}
while(strcmp(opcode,"END")){
if(strcmp(label,".")){ //若不是敘述就執行
while(fscanf(OP,"%s",checkOP)!=EOF){ //