hello everyone,
i'm new to computer science and i was challenged by one of my friends to find out the right code for a class file he gave me.
I have done some work on it but just need your help, this is not a homework assignment, its just for fun
if i'm thankful for anyone who helps me
this is my code
public class Tpi { private static final class Mode extends Enum { private enum Mode { UNKNOWN, COMPILE, INTERPRET } private static final Mode $VALUES[]; public static Mode[] values() { return (Mode[])$VALUES.clone(); } public static Mode valueOf(String s) { return (Mode)Enum.valueOf(Tpi$Mode, s); } static { UNKNOWN = new Mode("UNKNOWN", 0); COMPILE = new Mode("COMPILE", 1); INTERPRET = new Mode("INTERPRET", 2); $VALUES = (new Mode[] { UNKNOWN, COMPILE, INTERPRET }); } private Mode(String s, int i) { super(s, i); } } private static final int version = 1; private boolean success; private String sourceFile; private String destinationFile; private Mode mode; private static final String expectedSourceFileSuffix = ".p"; private static final String destinationFileSuffix = ".s"; public static void main(String args[]) { Tpi tpi = new Tpi(args); } private Tpi() { } public Tpi(String as[]) { success = false; mode = Mode.UNKNOWN; if(!decodeCommandLine(as)) { return; } else { Parser parser = new Parser(sourceFile); success = parser.isSuccessful(); return; } } public boolean isSuccessful() { return success; } private boolean decodeCommandLine(String as[]) { String s; int i = ".p".length(); System.out.println("Tpi version 1"); if(as.length != 2) { System.out.println("Invalid number of arguments."); explainArguments(); return false; } sourceFile = as[1]; if(sourceFile.length() < i + 1 || !".p".equals(sourceFile.substring(sourceFile.length() - i))) { System.out.println("sourcefile must end with .p"); explainArguments(); return false; } s = as[0]; if(!s.equals("-C")) { break } destinationFile = sourceFile.substring(0, sourceFile.length() - i); new StringBuilder(); this; destinationFile; ".s"; toString(); destinationFile; mode = Mode.COMPILE; System.out.println(new StringBuilder() + "Compiling " + sourceFile + " to " + destinationFile); break if(s.equals("-I")) { mode = Mode.INTERPRET; System.out.println((new StringBuilder()).append("Interpreting ").append(sourceFile).toString()); } else { System.out.println("Invalid mode."); explainArguments(); return false; } return true; } private void explainArguments() { System.out.println("Usage: java Tpi mode sourcefile.p"); System.out.println("where mode is one of the following:"); System.out.print("-C compiles sourcefile.p"); System.out.println(", writing assembly code to sourcefile.s"); System.out.println("-I interprets the contents of sourcefile.p"); } }
and i have attached the class file.
Thanx