* Write a program to implement Macro Processor. (Aif and ago not expected, nested macro calls not expected) with Error Handling: Macro Duplicate definition, Parameter Mismatching etc




Yüklə 11.65 Kb.
tarix28.02.2016
ölçüsü11.65 Kb.
/* Write a program to implement Macro Processor. (AIF and AGO not expected, nested macro calls not expected) with Error Handling: Macro Duplicate definition, Parameter Mismatching etc. */ #include #include #include struct MNT{ char MName[15]; int PP,KP,MDTP,KPDTP; }mnt[5]; struct KPDT{ char PName[15],Def[15]; }kpdt[15]; struct MDT{ char Label[15],Opcode[15],Value[35]; }mdt[25]; char PNT[10][10],APT[10][15]; int MDT_Ptr,MNT_Ptr,KPDT_Ptr; int PNT_Ptr,APT_Ptr,MEC; char Buffer[80],tok1[35],tok2[35],tok3[35],tok4[35]; char temp_op[40],temp[40],temp1[40],temp2[40],temp3[40]; int flag=0; int main_flag=0; FILE *fp1,*fp2; int SearchPNT(char *s){ int i; for(i=0;iM ADD BREG, M MOVEM CREG, M MEND MACRO EVAL &X,&Y,&Z MOVER AREG, &X SUB AREG, &Y ADD AREG, &Z MOVER AREG, &Z MEND MACRO CALC &X,&Y,&OP=MULT,&LAB= MOVER AREG, &X ADD AREG, &Y MOVEM AREG, &LAB MEND START MOVEM AREG, B EVAL A,B,C MOVEM AREG, N CALC P,Q,LAB=LOOP MOVEM AREG, N MAC1 ADD AREG, N CALC P,Q,OP=DIV,LAB=NEXT M DS 1 A DS 5 C DS 1 END /* OUTPUT Dj@Dj-Aspire-4720Z:~$ cd Desktop Dj@Dj-Aspire-4720Z:~/Desktop$ gcc -o p macr.c Dj@Dj-Aspire-4720Z:~/Desktop$ ./p PARAMETER NAME TABLE FOR MACRO MAC1 PNT empty PARAMETER NAME TABLE FOR MACRO EVAL # PName 0 X 1 Y 2 Z PARAMETER NAME TABLE FOR MACRO CALC # PName 0 X 1 Y 2 OP 3 LAB MACRO NAME TABLE # MName #PP #KP #MDTP KPDTP 0 MAC1 0 0 0 0 1 EVAL 3 0 4 0 2 CALC 2 2 9 0 KEYWORD PARAMETER DEFAULT TABLE # PName value 0 OP MULT 1 LAB MACRO DEFINATION TABLE # Label Opcode Oprand 0 MOVER AREG, M 1 ADD BREG, M 2 MOVEM CREG, M 3 MEND 4 MOVER AREG, (P,0) 5 SUB AREG, (P,1) 6 ADD AREG, (P,2) 7 MOVER AREG, (P,2) 8 MEND 9 MOVER AREG, (P,0) 10 ADD AREG, (P,1) 11 MOVEM AREG, (P,3) 12 MEND 13 MACRO WITH EXPANSION:: START MOVEM AREG, B +MOVER AREG,A +SUB AREG,B +ADD AREG,C +MOVER AREG,C MOVEM AREG, N +MOVER AREG,P +ADD AREG,Q +MOVEM AREG,LOOP MOVEM AREG, N +MOVER AREG,M +ADD BREG,M +MOVEM CREG,M ADD AREG, N +MOVER AREG,P +ADD AREG,Q +MOVEM AREG,NEXT M DS 1 A DS 5 C DS 1 END


Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©azrefs.org 2016
rəhbərliyinə müraciət

    Ana səhifə