A.3 The KJP Translator in a DOS Window


A.3 The KJP Translator in a DOS Window

The following steps will be repeated for every new source program that you write in KJP. A text editor is used to enter a new program in KJP or to modify an existing program in KJP.

For editing and using the KJP translator in a DOS window, complete the following steps:

  1. Start and open a DOS window. You can do this by clicking the Start button and then selecting Run. In the Run dialog box, type the word command and click the OK button.

  2. Change the directory to the one where the KJP files are stored. Use the CD command in DOS.

  3. Start the DOS editor. Figure A.2 shows a DOS window with the editor.

    click to expand
    Figure A.2: The DOS editor.

  4. Type and edit the source program (e.g., Cat.kpl) in KJP with the DOS editor.

  5. Invoke the KJP translator (also called the KJP compiler) to check syntax and convert your source program from KJP to Java. Type kjp Cat.kpl, where Cat.kpl is the source program coded in KJP. Note that the filename needs the kpl extension after the dot. See Figure A.3.

    click to expand
    Figure A.3: The DOS window with commands.

  6. After the KJP compiler runs, with the Windows Explorer, you will see in the current directory (or folder) two new files with the same name as your original source file. One of the files stores the syntax errors found. This file has the same name as the source program but with an err extension; for example, Cat.err.

  7. The second file contains the Java program; the file has the same name but with the java extension. For example, if your source program is Cat.kpl, then the Java program created is Cat.java.

  8. Use the Java compiler to compile the Java program (e.g. Cat.java) generated by the KJP translator.

  9. Use the Java virtual machine (JVM) to execute the compiled program. When starting execution, enter the input data to the program, if needed.

  10. Return to the Windows desktop by typing exit while in DOS.

In step 2 (DOS window), to change the directory to the one where you have the source programs in KJP, type the following command: cd\, and then press the Enter key. If the directory with your source programs is called my_files, on the next line type cd my_files and then press the Enter key; this changes to the directory called my_files. To get a list of the files in the current directory, type dir and then press Enter.

To start the DOS editor, type edit at the command prompt then press the Enter key. After the editor starts and if you are typing a new source program, start typing line by line; press the Enter key at the end of every line. When you have completed entering the text, click on the File menu and select the Save as option. Type the name of the file (program name). It must start with a capital letter, and have a .kpl extension. For example, Tarea.kpl. Figure A.2 shows the DOS editor with some text lines already entered. To exit the DOS editor, click the File menu, and then select Exit.

To compile (step 5 above) a source program in KJP called Salary.kpl, type kpl Salary.kpl and then press the Enter key. After a few seconds, you will see a message on the screen. In this case, File Salary.kpl, no syntax errors, lines processed: 45. The window in Figure A.3 shows these commands.

The KJP translator produces two new files with the same name as the original source program in KJP. The first file is the corresponding Java program. The other file created contains the syntax errors that the KJP compiler detected. The name of this file is the same as the source file but with the err extension. For example, after compiling the Salary.kpl source program, the error file produced is called Salary.err.

The error file generated by the KJP compiler shows all the syntax errors detected in the source program. These are indicated with the line number and column number where they appear. If there are no errors detected, then the last line of this text file includes the message no syntax errors. The total number of lines read is also shown

In summary, after invoking the KJP compiler, the new files that appear on the current directory are Salary.kpl, Salary.java, and Salary.err. You can check this with the dir command in DOS. You can also check the date with Windows Explorer.

To invoke the Java compiler and compile the file Salary.java, type javac Salary.java in DOS. After a few seconds, the Java compiler completes and displays error messages, if any. Take note of the error messages and go back to the DOS editor to correct them, by changing the source program in KJP.

If there are no error messages, run the program by invoking the Java Virtual Machine (JVM), and then type java Salary at the DOS prompt. Notice that you don't need the file extension. After a few seconds, your program starts execution.




Object-Oriented Programming(c) From Problem Solving to Java
Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)
ISBN: 1584502878
EAN: 2147483647
Year: 2005
Pages: 184

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net