using the oosiml/java compiler with eclipse

12
USING THE OOSIML/JAVA COMPILER With Eclipse Object Oriented Simulation with OOSimL Jos´ e M. Garrido Department of Computer Science College of Computing and Software Engineering Jan, 2020 College of Computing and Software Engineering Kennesaw State University c 2020 J. M. Garrido

Upload: others

Post on 03-Apr-2022

11 views

Category:

Documents


0 download

TRANSCRIPT

USING THE OOSIML/JAVA COMPILER

With Eclipse

Object Oriented Simulation with OOSimL

Jose M. Garrido

Department of Computer Science College of Computing and Software Engineering

Jan, 2020

College of Computing and Software EngineeringKennesaw State University

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 2

1 The OOSimL Compiler

This document briefly describes the features and explains how to use theOOSimL translator that generates Java code with the Eclipse IDE and sim-ply using a command window. The translation that generates C++ code isexplained in another document.

The OOSimL to Java compilation is a two-phase process. The first phaseinvolves a translation into an equivalent Java source program, the secondphase involves the corresponding Java compilation to Java byte-code.

Figure 1: First phase of compilation of an OOSimL program

The first phase of the compilation is illustrated in Figure 1. The secondphase of compilation involves compiling the corresponding Java program anduse of the Java compiler. Figure 2 shows what is involved in compilation ofa source program in Java. The Java compiler checks for syntax errors in thesource program and then translates it into a program in bytecode, which isthe program in an intermediate form.

Figure 2: Compiling a Java source program

Note that the Java bytecode is not dependent on any particular plat-form or computer system. This makes the bytecode very portable from onemachine to another.

Figure 3 shows how to execute a program in bytecode. The Java virtualmachine (JVM), which is another software tool from Sun Microsystems,carries out the interpretation of the program in bytecode.

The OOSimL compiler software, a sample model, and documentationare available from the OOSimL Web page:

http://ksuweb.kennesaw.edu/~jgarrido/oosiml.html

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 3

Figure 3: Executing a Java program

Currently, there are three general procedures used for developing pro-grams and simulation models with the OOSimL compiler. These proceduresare:

1. Developing the simulation model with the Eclipse integrated environ-ment.

2. Working with another integrated development environment (IDE).

3. Working in a Command window.

The next sections introduce and explain how to configure and use theOOSimL translator with the Eclipse development environment and a Com-mand window.

The OOSimL compiler software consists of two main components: anexecutable program, oosiml.exe, and the run-time library, oosimlib.jar.The compiler has the following functions:

1. Syntax checking of a source program in OOSimL; a list of errors isdisplayed and written to an error file with the same name as the sourceprogram

2. Generation of an equivalent program in Java

The first general step is to create a folder and then to store the relevantfiles in the folder. As mentioned previously, the two essential files are: theOOSimL compiler, which is an executable program called oosiml.exe, andthe runtime library, oosimlib.jar.

2 Developing Models with Eclipse

Building an Eclipse project enhances the OOSimL model development. AnEclipse plug-in was developed by Kevin Sealy for use with OOSimL; it canbe imported and set up to work with OOSimL projects. The features of thisplugin are:

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 4

• OOSimL keyword syntax highlighting

• OOSimL comments and description highlighting including importantOOSimL functions and important keywords.

• OOSimL content assist to prompt programmer with relevant choices

• Include functions and variables in the Content Outliner including codehighlighting when selecting an item in the content outliner.

This report describes the installation of Eclipse and the OOSimL editorplug-in. Additional information is provided that describes the process forconfiguring Eclipse to work with OOSimL projects. Finally, the featuresthat are built into the OOSimL editor plug-in are described in detail.

3 The Eclipse OOSimL Editor Plug-in

The Eclipse plugin is included in the archive oosimlc.zip and can be down-loaded from:

http://ksuweb.kennesaw.edu/~jgarrido/oosiml

After downloading, unzip the oosiml.zip. The Eclipse plug-in file in-cluded is edu.kennesaw.oosiml 1.0.1.jar.

Copy the plug-in file into the dropins directory of an Eclipse installationto install the plug-in. Restarting Eclipse after copying the file will installthe plug-in. The editor will automatically launch when opening a file withthe osl extension.

As mentioned previously, the OOSimL Editor plug-in will launch auto-matically when any file with an osl extension is opened. The editor pro-vides comment and OOSimL code syntax highlighting, content assist andan outline of the functions and variables in the content outliner to assist theOOSimL developer when creating simulation models.

4 Installing the OOSimL Compiler and Libraries

1. Create a new OOSimL workspace for Eclipse for your OOSimL projects.After starting Eclipse choose File and select Switch Workspace, thenOther from the Eclipse menu bar.

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 5

2. Create a new Java project. Choose File then select New. Select Projectand then select the Java Project wizard. Then click next and type ina project name like Carwash and click Finish.

3. Next, setup the OOSimL compiler and the project directory structure.Extract the OOSimL compiler oosiml.exe for Winows or oosiml.out forLinux and library file oosiml.jar from the archive file.

4.1 Installing the OOSimL compiler libraries

1. Refresh the Eclipse project by right clicking the project in the viewand choosing Refresh from the popup menu.

2. Open the project properties dialog by selecting the project name,choose the Project menu or right-clicking the project in the view andchoose Properties.

3. Select Java Build Path on the left and choose the Libraries tab. Thenclick the Add External Jars button and select oosimlib.jar from theappropriate directory.

4. Finally, click the OK button to save your changes.

4.2 To setup the OOSimL compiler

1. Choose Run and select External Tools, then select External Tools Con-figurations.

2. Choose the Program option on the left side followed by the new but-ton to create a new configuration. In the Name field, type OOSimL

Compiler.

3. Select the Browse File System button below the Location field, navi-gate to the appropriate directory and choose the directory with oosiml.exe.

4. Click the Browse Workspace button below the Working Directory fieldand choose the */src directory.

5. Finally, click the Variables button below the Argument field and chooseselected resource name.

6. Click the Apply button.

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 6

Figure 4: Eclipse main window

5 Compiling and Running the Carwash SampleProject

1. Extract the files from carwash.jar, save them in the Carwash/src di-rectory without creating a carwash directory inside the src directory.

2. If you are creating a project using existing OOSimL source files, thenselect Import from the File menu, and save the files inside the srcdirectory in the project folder.

To Extract files from a JAR archive:

1. On the current project, select the src folder.

2. Right-click on the src folder and select Import, or activate the Filemenu and select Import.

3. On the Import window, select General then Archive File.

4. Click the Next button.

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 7

5. In the Archive File window, on the input field “From archive file:”,click the Browse button to select the source folder and the (JAR)archive file. Click the Open button. On the input field “Into folder:”,make sure the src folder is selected on the current project folder.

6. On the left pane, expand the tree folder structure and click on thefolder (for example, carwash) that contains the desired files. On theright pane, select the desired files.

7. Move the files from the folder copied to the src folder of the project.

The Eclipse is now set up to compile and run the simulation project.

1. To compile an osl file, you can open a file or select a file in the view.

2. Then run the OOSimL compiler by choosing the Run menu, thenselecting External Tools, then selecting OOSimL Compiler.

3. The output from the compiler will show in the console view in thebottom of the Eclipse desktop.

4. Repeat this procedure for the each of the osl files.

Once all of the osl files are compiled, turn off the automatic build featureby selecting Build Automatically from the Project menu (this action willonly need to be completed once). Refresh the project again (right click theproject and choose refresh from the popup menu) and the compiled java fileswill now be visible in the default package folder.

Now choose Build Project from the Project menu to compile all of thejava files. The resulting class files will not be shown in the default viewof the project but they can be found in a bin directory located inside theCarwash directory in the file system. To run a model, activate the Runmenu and select Run As, then select Application.

6 Viewing the Carwash Simulation Results

After running the model, the output will show in the console window andthe final dialog will display some of the simulation run statistics. Refreshthe project one more time (right click the project and choose Refresh fromthe popup menu) and the carwstatf.txt and carwtrace.txt files will bevisible in the view. The files can then be opened to see the results of thesimulation run.

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 8

7 Syntax Highlighting

The OOSimL Editor plug-in provides syntax highlighting for both com-ments, OOSimL keywords, OOSiml classes and some keywords for classes,functions/methods and the main and Main body function names. Singleline comments and description comments will show in two different shadesof green. All keywords show in a purple color and the different OOSimLtypes (integer, double, string, etc) show in bold in the same color. AllOOSimL library classes are highlighted in a bold red color and a few of theOOSimL keywords in bold blue.

7.1 Content Assist

When editing an osl file content assist will provide a list of all of the OOSimLkeywords to assist without having to type the word. To trigger content assist,press the enter key while holding the ¡ctrl¿ key. Then select a word fromthe list to insert into the code.

7.2 Content Outline

The content outline view to the right side of the OOSimL editor viewworks together with the syntax highlighting feature to assist the devel-oper when modifying existing code. The content outline will show all func-tions/methods and any class and function/method variables and object ref-erences along with the beginning class statement and the endclass statement.When selecting an item in the content assist view, the code in the editorview will show the selected item highlighted in the left side of the view.When selecting the class, the entire view will be highlighted from the classstatement to the endclass statement. When a function is selected, the codefor only that method is highlighted and when a variable/object reference isselected, just the line for that variable or object reference will be highlighted.

8 Developing Models in a Command Window

In a Command window, any text editor can be used to enter a new programin OOSimL or to modify an existing OOSimL program. A good editor fordeveloping OOSimL and Java programs is Notepad++. For editing andusing the OOSimL compiler in a Command window, complete the followingsteps:

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 9

1. Start and open a Command window. You can do this by clicking theStart button and then selecting Run. In the Run window, type cmd

and click the OK button.

2. Change the directory to the one where your files are stored. Use theCD command.

3. Start the editor (on the Windows desktop).

4. Type and edit the source program (e.g., Carwash.osl) with the editor.Note that the source files have the .osl extension.

5. Invoke the OOSimL compiler to check syntax and generate a corre-sponding Java program. Type oosiml Carwash.osl. Note that thefilename needs the osl extension after the dot. See Figure 5.

6. In the current directory, (or folder) two new files appear with the samename as your original source file. One of the files stores the syntaxerrors found. This file has the same name as the source program butwith an err extension; for example, Carwash.err.

7. The second file contains the generated Java program; the file hasthe same name but with the java extension. For example, if yoursource program is Carwash.osl, then the Java program created isCarwash.java.

8. Use the Java compiler to compile the Java program (e.g. Carwash.java)generated by the OOSimL compiler.

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

10. Return to the Windows desktop by typing exit.

In step 2 (in a Command window), to change the directory to the onewhere you have the source programs, type the following command: cd\,and then press the Enter key. If the directory with your source programs iscalled eoosl, on the next line type cd eoosl and then press the Enter key;this changes to the directory called eoosl. To get a list of the files in thecurrent directory, type dir and then press Enter.

After the editor starts and if you are typing a new source program, starttyping line by line; press the Enter key at the end of every line. When you

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 10

Figure 5: OOSimL translation on a Command window

have completed entering the text, click on the File menu and select the Saveas option. Type the name of the file (program name). It must start with acapital letter, and have a .osl extension. For example, Carwash.osl.

To compile (step 5 above) an OOSimL source program called Carwash.osl,type oosiml Tarea.osl and then press the Enter key. After a few seconds,you will see a message on the screen. In this case, File Carwash.osl, nosyntax errors, lines processed: 182. The window in Figure 5 showsthese commands.

The OOSimL compiler generates two new files with the same name as theoriginal source program. The first file is the corresponding Java program.The other file created contains the syntax errors that the OOSimL compilerdetected. The first part of the name of this file is the same as the source filebut with the .err appended. For example, after compiling the Carwash.oslsource program, the Java file generated is Carwash.java and the error fileproduced is called Carwash.err.

The error file generated by the OOSimL compiler shows all the syntaxerrors detected in the source program. These are indicated with the linenumber and column number where they appear. If there are no errors de-tected, then the last line of this text file includes the message no syntax

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 11

Figure 6: Java compilation on a Command window

errors. The total number of lines read is also shownIn summary, after invoking the OOSimL compiler, the new files that ap-

pear on the current directory are Carwash.osl, Carwash.java, and Carwash.err.You can check this with the dir command. You can also check the date withWindows Explorer.

To invoke the Java compiler and compile the file Carwash.java, typejavac Carwash.java in DOS. After a few seconds, the Java compiler com-pletes and displays error messages, if any. Take note of the error messagesand go back to the editor to correct them, by editing the OOSimL sourceprogram.

Compiling simulation programs, involve setting the classpath for thecompiler to find the appropriate libraries, oosimlib.jar. Assume that thelibrary are located in the c:\eoosl directory and that the current directorycontains the Java classes for the simulation model, the following commandcompiles all the Java files in the current directory.

javac -classpath c:\eoosl\oosimlib.jar; *.java

The following command will start execution of the simulation model,

c© 2020 J. M. Garrido

Using the OOSimL/Java Compiler 12

assuming that the main class is named Carwash. See Figure 6.

java -classpath c:\eoosl\oosimlib.jar;. Carwash

c© 2020 J. M. Garrido