-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMacroPass1.txt
111 lines (90 loc) · 2.54 KB
/
MacroPass1.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
create java class file MACROPASS1 ----------------------------------------------------------------------------------------
import java.io.*;
import java.util.*;
public class MACROPASS1{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new FileReader("macro1.txt"));
FileWriter mnt=new FileWriter("mnt.txt");
FileWriter mdt=new FileWriter("mdt.txt");
FileWriter ir=new FileWriter("intermediate.txt");
LinkedHashMap<String, Integer> pntab=new LinkedHashMap<>();
String line;
String Macroname = null;
int mdtp=1,kpdtp=0,paramNo=1,pp=0,kp=0,flag=0;
while((line=br.readLine())!=null)
{
String parts[]=line.split("\\s+");
if(parts[0].equalsIgnoreCase("MACRO"))
{
flag=1;
line=br.readLine();
parts=line.split("\\s+");
Macroname=parts[0];
if(parts.length<=1)
{
mnt.write(parts[0]+"\t"+pp+"\t"+kp+"\t"+mdtp+"\t"+(kp==0?kpdtp:(kpdtp+1))+"\n");
continue;
}
for(int i=1;i<parts.length;i++) //processing of parameters
{
parts[i]=parts[i].replaceAll("[&,]", "");
//System.out.println(parts[i]);
}
mnt.write(parts[0]+"\t"+pp+"\t"+kp+"\t"+mdtp+"\t"+(kp==0?kpdtp:(kpdtp+1))+"\n");
//System.out.println("KP="+kp);
}
else if(parts[0].equalsIgnoreCase("MEND"))
{
mdt.write(line+"\n");
flag=kp=pp=0;
mdtp++;
paramNo=1;
}
else if(flag==1)
{
for(int i=0;i<parts.length;i++)
{
if(parts[i].contains("&"))
{
parts[i]=parts[i].replaceAll("[&,]", "");
mdt.write("(P,"+pntab.get(parts[i])+")\t");
}
else
{
mdt.write(parts[i]+"\t");
}
}
mdt.write("\n");
mdtp++;
}
else
{
ir.write(line+"\n");
}
}
br.close();
mdt.close();
mnt.close();
ir.close();
System.out.println("MAcro PAss1 Processing done. :)");
}
}
-----------------------------------------------------------------------------------------------------------
create empty intermediate.txt, mdt.txt and mnt.txt---------------------------------------------------------
----------------------------------------------------------------------------------------------------------
create macro1.txt and add following contents---------------------------------------------------------------
START
MACRO
INCR &ARG3 &ARG2
ADD AREG &ARG1
MOVER BREG &ARG1
MEND
MACRO
PVG &ARG2 &ARG1
SUB AREG &ARG2
MOVER CREG & ARG1
MEND
INCR
DECR
DATA2
END