Results 1 to 7 of 7
  1. #1
    0_0
    0_0 is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default 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

    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");
        }
    }
    and i have attached the class file.


    Thanx
    Attached Files Attached Files

  2. #2
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    5

    Default

    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.

  3. #3
    0_0
    0_0 is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    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

  4. #4
    0_0
    0_0 is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    anyone can HELP?!

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    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?

  6. #6
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by 0_0 View Post
    anyone can HELP?!

    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");
        }
    }

  7. #7
    0_0
    0_0 is offline Member
    Join Date
    Mar 2010
    Posts
    4
    Rep Power
    0

    Default

    okay thanx for your help, i'll try my best to fix it

    thanx

Similar Threads

  1. question in java program
    By Moiz in forum New To Java
    Replies: 1
    Last Post: 09-13-2009, 11:33 PM
  2. Replies: 1
    Last Post: 07-03-2009, 08:41 PM
  3. java inner class question
    By neo_in_matrix in forum New To Java
    Replies: 9
    Last Post: 02-15-2009, 05:08 PM
  4. Question/Java Program
    By icedragon770 in forum Java Applets
    Replies: 7
    Last Post: 10-13-2008, 06:12 AM
  5. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 09:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •