-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathala.java
More file actions
152 lines (143 loc) · 3.74 KB
/
ala.java
File metadata and controls
152 lines (143 loc) · 3.74 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import java.util.*;
import java.io.*;
class MntTuple {
String name;
int index;
MntTuple(String s, int i) {
name = s;
index = i;
}
public String toString() {
return("[" + name + ", " + index + "]");
}
}
class MacroPass1 {
static List<MntTuple> mnt;
static List<String> mdt;
static int mntc;
static int mdtc;
static int mdtp;
static BufferedReader input;
static List<List <String>> ala;
static Map<String, Integer> ala_macro_binding;
public static void main(String args[]) throws Exception {
initializeTables();
System.out.println("===== PASS 1 =====\n");
pass1();
}
static void pass1() throws Exception {
String s = new String();
input = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\Users\\dell\\Desktop\\input.txt")));
PrintWriter output = new PrintWriter(new FileOutputStream("output_pass1.txt"), true);
while((s = input.readLine()) != null) {
if(s.equalsIgnoreCase("MACRO")) {
processMacroDefinition();
} else {
output.println(s);
}
}
System.out.println("ALA:");
showAla(1);
System.out.println("\nMNT:");
showMnt();
System.out.println("\nMDT:");
showMdt();
}
static void processMacroDefinition() throws Exception {
String s = input.readLine();
String macro_name = s.substring(0, s.indexOf(" "));
mnt.add(new MntTuple(macro_name, mdtc));
mntc++;
pass1Ala(s);
StringTokenizer st = new StringTokenizer(s, " ,", false);
String x = st.nextToken();
for(int i=x.length() ; i<12 ; i++) {
x += " ";
}
String token = new String();
int index;
token = st.nextToken();
x += token;
while(st.hasMoreTokens()) {
token = st.nextToken();
x += "," + token;
}
mdt.add(x);
mdtc++;
addIntoMdt(ala.size()-1);
}
static void pass1Ala(String s) {
StringTokenizer st = new StringTokenizer(s, " ,", false);
String macro_name = st.nextToken();
List<String> l = new ArrayList();
int index;
while(st.hasMoreTokens()) {
String x = st.nextToken();
if((index = x.indexOf("=")) != -1) {
x = x.substring(0, index);
}
l.add(x);
}
ala.add(l);
ala_macro_binding.put(macro_name, ala_macro_binding.size());
}
static void addIntoMdt(int ala_number) throws Exception {
String temp = new String();
String s = new String();
List l = ala.get(ala_number);
boolean isFirst;
while(!s.equalsIgnoreCase("MEND")) {
isFirst = true;
s = input.readLine();
String line = new String();
StringTokenizer st = new StringTokenizer(s, " ,", false);
temp = st.nextToken();
for(int i=temp.length() ; i<12 ; i++) {
temp += " ";
}
line += temp;
while(st.hasMoreTokens()) {
temp = st.nextToken();
if(temp.startsWith("&")) {
int x = l.indexOf(temp);
temp = ",#" + x;
isFirst = false;
} else if(!isFirst) {
temp = "," + temp;
}
line += temp;
}
mdt.add(line);
mdtc++;
}
}
static void showAla(int pass) throws Exception {
PrintWriter out = new PrintWriter(new FileOutputStream("out_ala_pass" + pass + ".txt"), true);
for(List l : ala) {
System.out.println(l);
out.println(l);
}
}
static void showMnt() throws Exception {
PrintWriter out = new PrintWriter(new FileOutputStream("out_mnt.txt"), true);
for(MntTuple l : mnt) {
System.out.println(l);
out.println(l);
}
}
static void showMdt() throws Exception {
PrintWriter out = new PrintWriter(new FileOutputStream("out_mdt.txt"), true);
for(String l : mdt) {
System.out.println(l);
out.println(l);
}
}
static void initializeTables() {
mnt = new LinkedList();
mdt = new ArrayList();
ala = new LinkedList();
mntc = 0;
mdtc = 0;
ala_macro_binding = new HashMap();
}
}