make intrepreter with Java

How to make intrepreter with Java

Page 1 of 1

3 Replies - 4209 Views - Last Post: 12 November 2010 - 10:19 PM Rate Topic: -----

#1 JaCod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-October 10

make intrepreter with Java

Posted 11 November 2010 - 08:09 PM

some time now I'm confused how to make the Interpreter or execute the program after the compilation process.
The following piece of program for the compilation process
public void actionPerformed(ActionEvent e) {
            try {
            input=txinput.getText();
            txresult.append(input);
            FileWriter save=new FileWriter(new File("file.java"));
            save.write(input);
            save.close();

            Process pid = Runtime.getRuntime().exec("file.java");
	    BufferedReader in = new BufferedReader(new InputStreamReader(pid.getErrorStream()));

            String hasil;
	    txresult.setText("Result:\n");
	    while((result=in.readLine())!=null) {
	    txresult.append(hasil);
	    txresult.append(System.getProperty("line.separator"));
	}
	if ((result=in.readLine())==null) {
	txresult.append("Source success compiled");
	}
	in.close();

           }
            catch(IOException eu){
             JOptionPane.showMessageDialog(null,eu);
}
}
});




From the plot above, after saving a file in the development of the extension. Java, then it will be the compilation. Incidentally, I wonder how to make the process of Interpreter or execution entered in the code.

Here's how if we want to compile
javac (then the name of java file which will be compiled)


From here I do not understand, what if the Interpreter or the execution of the program?

This post has been edited by JaCod: 11 November 2010 - 08:16 PM


Is This A Good Question/Topic? 0
  • +

Replies To: make intrepreter with Java

#2 bcranger  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 252
  • View blog
  • Posts: 1,199
  • Joined: 01-February 10

Re: make intrepreter with Java

Posted 11 November 2010 - 09:36 PM

There is no way to compile your present code...all code must be in classes, you cannot just slap some code down and expect it to run.
public class Test
{
  public Test()
  {}
  // runner method must have a main method
  public static void main(String[] args)
  {}
}


Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10467
  • View blog
  • Posts: 38,794
  • Joined: 27-December 08

Re: make intrepreter with Java

Posted 11 November 2010 - 09:59 PM

In order to run the code your IDE saves, it needs to use the Process class to compile the code by calling javac. The following commands should be executed by your Process objects:
javac FileName.java //compiles the file
java FileName //runs the file



@bcranger: His project is to make a simple Java IDE. :)
Was This Post Helpful? 1
  • +
  • -

#4 JaCod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-October 10

Re: make intrepreter with Java

Posted 12 November 2010 - 10:19 PM

View Postmacosxnerd101, on 11 November 2010 - 08:59 PM, said:

In order to run the code your IDE saves, it needs to use the Process class to compile the code by calling javac. The following commands should be executed by your Process objects:
javac FileName.java //compiles the file
java FileName //runs the file



@bcranger: His project is to make a simple Java IDE. :)


in my code correct
Process pid = Runtime.getRuntime().exec("javac file.java");

code generates a compilation of results, if correct will appear "Source compiled success" and if one will display an error message.

I mean if I change
Process pid = Runtime.getRuntime().exec("java file");


will appear an error in execution. is there any advice on how to enter code execution?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1