package assembler;
import java.io.*;
public class Pass1 {
public static void main(String[] args) throws IOException {
String[][] a = {
{"", "START", "101", ""},
{"", "MOVER", "BREG", "ONE"},
{"AGAIN", "MULT", "BREG", "TERM"},
{"", "MOVER", "CREG", "TERM"},
{"", "ADD", "CREG", "N"},
{"", "MOVEM", "CREG", "TERM"},
{"N", "DS", "2", ""},
{"RESULT", "DS", "2", ""},
{"ONE", "DC", "1", ""},
{"TERM", "DS", "1", ""},
{"", "END", "", ""}
};
int lc = Integer.parseInt(a[0][2]);
// Symbol table
String[][] st = new String[10][2];
int symCnt = 0;
BufferedWriter symtab = new BufferedWriter(new FileWriter("symtab.txt"));
BufferedWriter inter = new BufferedWriter(new
FileWriter("intermediate.txt"));
for (int i = 1; i < a.length; i++) {
if (!a[i][0].equals("")) {
st[symCnt][0] = a[i][0];
st[symCnt][1] = Integer.toString(lc);
symtab.write(a[i][0] + "\t" + lc + "\n");
symCnt++;
}
inter.write(lc + "\t" + a[i][1] + "\t" + a[i][2] + "\t" + a[i][3] + "\
n");
if (a[i][1].equals("DS")) {
lc += Integer.parseInt(a[i][2]);
} else {
lc++;
}
}
symtab.close();
inter.close();
System.out.println("Pass-I complete. Symbol Table and Intermediate Code
generated.");
}
}