Results 1 to 7 of 7
- 03-19-2010, 01:57 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 4
- Rep Power
- 0
JAVA Program Question! .class file
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
and i have attached the class file.Java 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"); } }
Thanx
- 03-19-2010, 02:16 PM #2
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
none of the class files run. Only Tpi has a main() and it needs Tpi$Mode. And I'm also confused about what you are asking us to do.
- 03-21-2010, 06:57 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 4
- Rep Power
- 0
this is the code from the decompiler
Java Code:import java.io.PrintStream; public class Tpi { private static final class Mode extends Enum { public static final Mode UNKNOWN; public static final Mode COMPILE; public static final Mode 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 MISSING_BLOCK_LABEL_208; } destinationFile = sourceFile.substring(0, sourceFile.length() - i); new StringBuilder(); this; JVM INSTR dup_x1 ; destinationFile; append(); ".s"; append(); toString(); destinationFile; mode = Mode.COMPILE; System.out.println((new StringBuilder()).append("Compiling ").append(sourceFile).append(" to ").append(destinationFile).toString()); break MISSING_BLOCK_LABEL_270; 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 the code in the main post is my code.
the response after runing the java file from my code is:
tpi.java:97: ';' expected
break^
tpi.java:101: not a statement
^this;
tpi.java:102: not a statement
^destinationFile;
tpi.java:103: not a statement
^".s";
tpi.java:105: not a statement
^destinationFile;
tpi.java:108: ';' expected
break^
6 errors
the response of the decompiled .class file.
tpi.java:102: not a statement
^this;
tpi.java:103: not a statement
JVM INSTR^dup_x1 ;
tpi.java:103: not a statement
JVM INSTRd^up_x1 ;
tpi.java:104: not a statement
^destinationFile;
tpi.java:106: ';' expected
".s";
tpi.java:109: not a statement
^destinationFile;
6 errors
i hope someone can help
thanx
- 04-06-2010, 04:05 AM #4
Member
- Join Date
- Mar 2010
- Posts
- 4
- Rep Power
- 0
anyone can HELP?!
- 04-06-2010, 12:14 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Still not sure what you're expecting here...
Doesn't help you're not showing us where the errors are...have you tried to sort out the compilation errors at all?
- 04-06-2010, 04:21 PM #6
i inserted your code in eclipse and my comments in red are not errors at compile time but errors that eclipse recognized. without examining the semantic i must say that the syntax is a disaster. i'm not sure if i got all errors, but these are enough to show how bad the code is ...
Java Code:import java.io.PrintStream; public class Tpi { private static final class Mode extends Enum [COLOR="Red"]// the type mode may not subclass Enum explicitly[/COLOR] { public static final Mode UNKNOWN; public static final Mode COMPILE; public static final Mode 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); [COLOR="Red"]// Tpi$Mode cannot be resolved[/COLOR] } 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); [COLOR="Red"] // The constructor Object(String, int) is undefined[/COLOR] } } 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); // Parser cannot be resolved by a type[/COLOR] 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 MISSING_BLOCK_LABEL_208; } destinationFile = sourceFile.substring(0, sourceFile.length() - i); new StringBuilder(); this; [COLOR="Red"]// The left-hand side of an assignment must be a variable[/COLOR] JVM INSTR dup_x1 ;[/COLOR] [COLOR="Red"]// The JVM cannot be resolved to a type[/COLOR] destinationFile; [COLOR="Red"] // insert "AssignmentOperator Expression" to complete expression[/COLOR] append(); [COLOR="Red"] // undefined for the type Tpi [/COLOR] ".s"; [COLOR="Red"] // insert "Assignment Operator" to complete expression[/COLOR] append(); [COLOR="Red"]// undefined for the type Tpi [/COLOR] toString(); destinationFile; [COLOR="Red"] // insert "AssignmentOperator Expression" to complete expression[/COLOR] mode = Mode.COMPILE; System.out.println((new StringBuilder()).append("Compiling ").append(sourceFile).append(" to ").append(destinationFile).toString()); break MISSING_BLOCK_LABEL_270; 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"); } }
- 04-06-2010, 11:23 PM #7
Member
- Join Date
- Mar 2010
- Posts
- 4
- Rep Power
- 0
Similar Threads
-
question in java program
By Moiz in forum New To JavaReplies: 1Last Post: 09-13-2009, 11:33 PM -
could not find main class, the program wil exit-- error in jar file
By nishant.4545 in forum Advanced JavaReplies: 1Last Post: 07-03-2009, 08:41 PM -
java inner class question
By neo_in_matrix in forum New To JavaReplies: 9Last Post: 02-15-2009, 05:08 PM -
Question/Java Program
By icedragon770 in forum Java AppletsReplies: 7Last Post: 10-13-2008, 06:12 AM -
To open an image file such as Jpeg file using JAva Program
By itmani2020 in forum Advanced JavaReplies: 10Last Post: 07-11-2008, 09:57 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks