SPOSL2
SPOSL2
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
class TableRow {
String symbol;
int address;
int index;
super();
this.symbol = symbol;
this.address = address;
super();
this.symbol = symbol;
this.address = address;
this.index = index;
return index;
this.index = index;
this.symbol = symbol;
return address;
this.address = address;
public Pass_2() {
try {
pass2.generateCode("IC.txt");
System.out.println("IC");
pass2.printPass2Output("IC.txt");
System.out.println("Literal table");
pass2.printPass2Output("LITTAB.txt");
System.out.println("Symbol table");
pass2.printPass2Output("SYMTAB.txt");
System.out.println("Machine Code");
pass2.printPass2Output("PASS2.txt"); // Print PASS2.txt content after generation
} catch (Exception e) {
e.printStackTrace();
BufferedReader br;
String line;
try {
br.close();
br.close();
} catch (Exception e) {
System.out.println(e.getMessage());
readtables();
if (parts[0].contains("AD") || parts[0].contains("DL,02")) {
bw.write("\n");
continue;
} else if (parts.length == 2) {
if (parts[0].contains("DL")) {
if (Integer.parseInt(parts[0]) == 1) {
bw.write(code);
} else if (parts[0].contains("IS")) {
if (opcode == 10) {
if (parts[1].contains("S")) {
bw.write(code);
} else if (parts[1].contains("L")) {
bw.write(code);
bw.write(code);
bw.write(code);
} else if (parts[2].contains("L")) {
bw.write(code);
bw.close();
br.close();
try {
String line;
System.out.println(line);
br.close();
} catch (IOException e) {
e.printStackTrace();
-------------------------------------------------------------------
OUTPUT:
IC
(AD,01) (C,100)
(IS,04) 1 (L,1)
(IS,05) 2 (S,02)
(IS,01) 1 (L,2)
(DL,01) (C,5)
(DL,01) (C,2)
(IS,04) 1 (S,03)
(DL,01) (C,5)
(DL,02) (C,2)
(AD,02)
Literal table
1 5 104
2 2 105
Symbol table
1 L1 100
2 X 106
3 Y 107
Machine Code
04 1 104
05 2 106
01 1 105
00 0 005
00 0 002
04 1 107
00 0 005