#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){ //