0% found this document useful (0 votes)
7 views3 pages

C Macro Processor Pass 2 Code

Uploaded by

GIFT MUTEREKO
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

C Macro Processor Pass 2 Code

Uploaded by

GIFT MUTEREKO
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Pass 2 of 2 pass Macro Processor in C

1. #include<stdio.h>
2. #include<conio.h>
3. #include<string.h>
4. #include<stdlib.h>
5. void main()
6. {
7. FILE *f1,*f2,*f3,*f4,*f5;
8. int i,len;
9. char mne[20],opnd[20],la[20],name[20],mne1[20],opnd1[20],arg[20];
10. clrscr();
11. f1=fopen("[Link]","r");
12. f2=fopen("[Link]","r");
13. f3=fopen("[Link]","r");
14. f4=fopen("[Link]","w+");
15. f5=fopen("[Link]","w");
16. fscanf(f1,"%s%s%s",la,mne,opnd);
17. while(strcmp(mne,"END")!=0)
18. {
19. if(strcmp(mne,"MACRO")==0)
20. {
21. fscanf(f1,"%s%s%s",la,mne,opnd);
22. while(strcmp(mne,"MEND")!=0)
23. fscanf(f1,"%s%s%s",la,mne,opnd);
24. }
25. else
26. {
27. fscanf(f2,"%s",name);
28. if(strcmp(mne,name)==0)
29. {
30. len=strlen(opnd);
31. for(i=0;i<len;i++)
32. {
33. if(opnd[i]!=',')
34. fprintf(f4,"%c",opnd[i]);
35. else
36. fprintf(f4,"\n");
37. }
38. fseek(f2,SEEK_SET,0);
39. fseek(f4,SEEK_SET,0);
40. fscanf(f3,"%s%s",mne1,opnd1);
41. fprintf(f5,".\t%s\t%s\n",mne1,opnd);
42. fscanf(f3,"%s%s",mne1,opnd1);
43. while(strcmp(mne1,"MEND")!=0)
44. {
45. if((opnd1[0]=='&'))
46. {
47. fscanf(f4,"%s",arg);
48. fprintf(f5,"-\t%s\t%s\n",mne1,arg);
49. }
50. else
51. fprintf(f5,"-\t%s\t%s\n",mne1,opnd1);
52. fscanf(f3,"%s%s",mne1,opnd1);
53. }
54. }
55. else
56. fprintf(f5,"%s\t%s\t%s\n",la,mne,opnd);
57. }
58. fscanf(f1,"%s%s%s",la,mne,opnd);
59. }
60. fprintf(f5,"%s\t%s\t%s\n",la,mne,opnd);
61. fclose(f1);
62. fclose(f2);
63. fclose(f3);
64. fclose(f4);
65. fclose(f5);
66. printf("pass2");
67. getch();
68. }
69.

Input files:

[Link]
EX1 MACRO &A,&B
- LDA &A
- STA &B
- MEND -
SAMPLE START 1000
- EX1 N1,N2
N1 RESW 1
N2 RESW 1
- END -

[Link]
EX1 &A,&B
LDA &A
STA &B
MEND

[Link]
EX1

Output files:

[Link]
N1
N2
[Link]
SAMPLE START 1000
. EX1 N1,N2
- LDA N1
- STA N2
N1 RESW 1
N2 RESW 1
- END

You might also like