Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.8 kB
2
Indexable
Never
package pass1;

import java.io.*;
import java.util.*;

public class pass1
{
	public static void main(String[] args)
	{
		Vector<String> pntab = new Vector<String>();
		Vector<String> kpdtab = new Vector<String>();
		Vector<MNT> mnt = new Vector<MNT>();
		Vector<MDT> mdt = new Vector<MDT>();
	 	
        try
        {
            File Obj = new File("pass1.txt");
            Scanner Reader = new Scanner(Obj);
    		boolean begin = false;
            while (Reader.hasNextLine())
            {
                String data = Reader.nextLine();
                String[] tokens = data.split("\t");
                if(tokens[0] == "MACRO")
                {
                	begin = true;
                	continue;
                }
            	if(begin)
            	{
            		int pp = 0;
            		int kp = 0;
            		int mdtp = mdt.size();
            		int kpdtp = kpdtab.size();
            		String name = tokens[0];
            		for(int i=1; i<tokens.length; i++)
            		{
            			if(tokens[i].contains("="))
            			{
            				kp++;
            				String[] temp = tokens[i].split("=");
            				if(temp.length == 2)
            					kpdtab.add(temp[1]);
            				else
            					kpdtab.add("");
            				pntab.add(temp[0].replace("&", ""));
            			}
            			else
            			{
            				pp++;
            				pntab.add(tokens[i].replace("&", ""));
            			}
            		}
            		if(kp == 0)
            			kpdtp = -1;
            		begin = false;
            		MNT obj = new MNT(name, pp, kp, mdtp, kpdtp);
            		mnt.add(obj);
            	}
            	else
            	{
            		if(tokens.length == 1)
            		{
            			MDT obj = new MDT("MEND", " ", " ");
            			mdt.add(obj);
            			pntab.clear();
            			continue;
            		}
            		else
            		{
            			String operand1;
            			String operand2;
            			String n = tokens[0];
            			if(tokens[1].contains("="))
            			{
            				operand1 = tokens[1];
            			}
            			else
            			{
                			int a = pntab.indexOf(tokens[1].replace("&", ""));
                			operand1 = "p," + a;
            			}
            			if(tokens[2].contains("="))
            			{
            				operand2 = tokens[2];
            			}
            			else
            			{
                			int a = pntab.indexOf(tokens[2].replace("&", ""));
                			operand2 = "p," + a;
            			}
            			MDT obj = new MDT(n, operand1, operand2);
            			mdt.add(obj);
            			continue;
            		}
            	}
            }
            Reader.close();
        }
        catch (FileNotFoundException e)
        {
            System.out.println("File not found or error opening the file!!");
        }
        
        try
        {
        	FileWriter writer = new FileWriter("MNT.txt", true);
        	for(int i=0; i<mnt.size(); i++)
        	{
        		MNT obj = mnt.get(i);
        		writer.write(obj.name + "\t" + obj.pp + "\t" + obj.kp + "\t" + obj.mdtp + "\t" + obj.kpdtp + "\n");
        	}
        	writer.close();
        }
        catch(IOException e)
        {
        	System.out.println("An error has occurred.");
        }
        
        try
        {
        	FileWriter writer = new FileWriter("KPDTAB.txt", true);
        	for(int i=0; i<kpdtab.size(); i++)
        	{
        		KPDTAB obj = mnt.get(i);
        		writer.write(obj.name + "\t" + obj.pp + "\t" + obj.kp + "\t" + obj.mdtp + "\t" + obj.kpdtp + "\n");
        	}
        	writer.close();
        }
        catch(IOException e)
        {
        	System.out.println("An error has occurred.");
        }
	}
}