Eclipsechun Project

Total Page:16

File Type:pdf, Size:1020Kb

Eclipsechun Project

EclipseChun project

By

Chun ping Wang. Abstract

A compiler is a tool that converts readable human language into machine byte code so that it can be run. However, a compiler is not enough, as it does not allow users to edit the language while it is being built. What we need is a nice IDE that allows users to run and compile their program in the same window. This leads to two paths, create an IDE yourself or use an already existing IDE such as Eclipse. The smarter choice would be to use what already is working and this program does just that.

I. Introduction

This is a plug-in for Eclipse to add c-- language recognition. Some capabilities of c-- include basic math operation, interaction with the users and complex branch instructions including the newly added "for" loop. The language lacks the ability to do functions or subprograms and complex math operations. Only three different types are allowed, String, Integer, and Float. It follows traditional commenting style of // and /* like Java and C++. Eclipse is an IDE tool similar to JBuilder but with the important capability to allow programmers to add on the IDE. It includes a GUI for users to create a new add on to the Eclipse IDE itself. The plug-in also sets Chuntext editor as the default editor of c-- type files. In addition it adds to the eclipse menu several functions that were purposely made for testing and education.

II. Technological background A. Java is a programming language that is "platform independent". Programs created in java will run on any Java Virtual machine. The project is written with JRE 1.5.0 but it is compatible with JDK 1.4.2. See appendix A for more info B. Eclipse is the IDE that this program is built on. It is an open source IDE that was built to make Java projects. However it also has capability to recognize different languages and features such as C++ and CSharp. This is done through Eclipse plug-in development. The program must have Eclipse 3.1M3 installed. You could probably get by with Eclipse 3.0. A backup editor is created for those who don't have Eclipse but users will not get full functionality. See Appendix A for more info. C. JLex is a lexical analyzer created for java written in java. A lexical Analyzer converts a stream of characters into tokens. This makes it easier later on to check if the characters are allowed in the c-- language. See Appendix A for more info. D. Yet another compiler compiler (YACC) is a utility written in C for C to generate a parser for the inputted language. The table is generated in LALR (1) format, which allows disambiguates in the grammar. Most UNIX type operating system should have YACC. See Appendix A for more info E. GEF is the graphical editor framework for Eclipse. Although this program never really uses GEF, most of its concept originated from it. See appendix A for more information. F. XML is the language for the “plugin.xml” files. The language is derived from SGML. It was originally design to meet the need of large scale publishing with the ease of implementation. For more information, see appendix A. III. System Requirements

The program is design to run on the X86 platform. Although programs written in java are portable, it is recommended that you install the plug-in on a desktop computer. This is also ensures quality performance since testing was not done on any non X 86 platform. o Other recommended requirements are to have 1 GHz with minimum of 5 megabytes of free space + 300 megabyte of recommended space to install eclipse o Compilation time is slow so 32 DRAM or RAM or memory is recommended. o Additional tools that may be required for the plug-in to be fully effective are GEF and Eclipse model framework. o It is recommended that you have JRE 1.5.0 but having JDK 1.4.0 should be sufficient enough. o

II. Design and implementation details

A. GUI DESIGN

The toolbar will contain 6 icons for quick access to the compiler tools.

Clicking on the icon will check your program to find any

unknown characters. Clicking on the icon will compile the code that you written. Finally clicking on the icon will compile and run your code. You may see similar icons on the right hand side. The icons on the left side are for files with c-- extension while the icons on the right side are for files with .enc extension. The .enc extension is the encrypted format of .c--. The menu “ChunText” is the main compiling menu. The “cs201 to cs312” menu contains programs that I’ve written from cs201 to cs312. The “Misc Math” menu contains interactive programs that demonstrate ideas from Math 103 or below such as finding Greatest Common Denominator (gcd) and Least Common Multiples (lcm). The security menu contains tools that can be used to decrypt .enc files to compile into .c--. Finally the “Sample GUI” menu is just random GUI samples. Here is the main eclipse frame with the plug-in install

A. User DESIGN 1. To compile the code that you written, go find the menu ChunText  parsing. 2. To check for spelling, go to the menu ChunText --> spelling. 3. To run the program, go to the menu ChunText --> run. 4. To view this documentation, go to show  view  select others. Under it open the sample view and select Help View. 5. There are other tools you can see in the menu but they are programs in the experimental stage and are not necessary working properly. B. Coding design. 1. Parser Table was created using the Java.util.Vector class. The type of method used is LALR parsing for top down approach. To validate the symbol table a binarySearchTree was used for quick access and improve run time capability. 2. JLex generated the lexer information. No actual code was actually written besides inputting the symbol token and its index number inside of it. Link. 3. Plugin.xml describes the view in eclipse interface. It contains the description of the menu and how eclipse graphic interface should be extended. 4. The Java AWT was used to create a dummy text editor and the SWT library was used in designing the documentation view that you are seeing right now. 5. As for the algorithm, the program separates the domain from the domain logic. This concept is also known as the model view controller. This was easily done through Eclipse plugin description, which will be described later on. C. Console box and help view: The console box is a popup window that sorts of runs like command line. It different from a regular console box as it does not run inside the eclipse console but rather in a new frame window. The help view just display documentation inside eclipse. To activate it, go to Eclipse, show-view others. Then select Samples folder and inside it should be something called help-view.

Here is the console view.

V. Empirical Study. D. Experimental setup 1. Test1: Test to see if program display the error the right way. Used gcm.c-- and gcm2.c--. One was undeclared variable and the other was unclosed loop. 2. Test2: Test to see if program can run in command line. This test was to allow user to run the compiler without using the eclipse extension dependency 3. Test3: Test to see if program actually finds the error. 4. Test 4: See if the program can run outside of eclipse. 5. Test 5: See if it is actually x86 system or internal error in plugin. 6. Test 6: See if Eclipse could launch ChunText as the default editor for .c— files. 7. Test 7: Test 7 was to see if the program handles divide by zero error. E. Experimental result 1. Test1: The program gives confusing information about the error. On first try it would give an error in terms of token numbers. On a second try it would display the wrong line number. On a third try it gives at least a satisfying error message. Not a good one but at least ok. Telling the user the type of error, and the line that has the error. 2. Test 2: The program wouldn't even run on command line because there was a dependency on some of the eclipse classes. Change the coding to once again have it running in command line. Argument passed must be a .c-- file or else it would give an error. Future extension is to link classpath, so program would be able to run on command line, though the dependency of eclipse makes it difficult. In addition of running this test, the program will open a new dialog prompting the user to select .c-- file. Goal has been made to associate this editor with .c-- files association. 3. Test 3: Due to serious refactoring in the code, there was a need to see if the compiler still works. Of all 3 tests, this one gives the best output. 4. This test although passed the results on first try, fails the second time. Problem must be that eclipse does not allow any extension that does not work properly. The first try was run on desktop computer and the second try was test on laptop computer. There could be possible restriction that plugin could only be install on an X86 system. 5. The result of 5th test shows there are some internal errors in the plugin. The Plugin.xml does not upgrade the current Graphic user interface of Eclipse as it should have. 6. The result of the 6th test was at first not what I wanted. It gives an error that ChunText could not be launched. The error later on turns out to be that there was no launcher for the editor. After fixing the problem and retesting, the only problem would be opening the file in .c—format. If a file is inside a project, Eclipse would recognize it. However if you tried to open an existing file that has .c—extension then the editor would not launch the file. 7. The program will catch divide by zero error and treat it as infinite. F. Analysis: The program currently still has some bugs. Code has been carefully separated to allow easier readability of the code. As for the main problem, it is trying to get the program to display the error in the eclipse problem view. This allows users to directly click on the problem and it will go to the line. Also there is a need to display more than one error. Finally, some mathematical tests such as checking for negative root were not done because the c—language does not have the capability to do square roots.

VI. Function API.

a.DoLex (String arg) function reads from a file and checks the lexical table to see if there are any tokens that does not exist inside the lexical table. If it happens to see a “/*” then it will ignore any type of lexical error until it sees “*/”. If it sees a “//” then it will ignore all errors until it sees the end of line. It creates a new *.token file that contains all the tokens of the inputted file with its corresponding token value. DoLex returns a list of important information to be used by the parser. b. DoParse (String filename) function reads a file and checks to see if there are any grammatical errors, that is, if each nonterminal will end up reducing to a terminal base on the parsing table. In addition it makes sure variables are declared in the declaration phase before they can be use and parameter passed into “for” happens to be an integer. The step by step reduction process is generated in the *.parser file. c.CodeGeneration (String filename) function takes a file, compiles it using DoParse function and then runs it. Unlike DoParse and DoLex its cousin, CodeGeneration does not do hardcore exception or error checking. It runs the program using low- level assembly style execution. It generates a *.attribute file containing the list of quadruple to be executed. Programmers can check the file as a tool to debug and trace their program. d. Run (IAction action) function runs the program from the Eclipse menu. Any file that needs to be run from menu must implement this function. e.Open (IPath file) function in Helloworld.cminuslauncher opens the currently active file with the ChunText editor. It uses the toOSString method to set the current file name as information to be used by the ChunText editor. f. ReadAtLine (String file, int linenumber) function reads from a file and return what appears in that specify line. It sees the first line as line 0 and second line as line 1 and so on… g. CloseConsole () function will close the currently active AWT console box. It will only close if the console exists. To save space, it is recommended that each console box is close before you open a new one. h. CreatePartControl (Composite parent) function describes the view to be launch by Eclipse. Currently this function does not work and is in the process of being tool around with. VII. Conclusion and future work

I have come to the conclusion that this project still needs a lot of work. Future works will include renovating this project to be design into something useful. Possible upgrades could include displaying the error inside the Problems view of eclipse and creating an error log. There is also the possibility of upgrading to allow this program to run on any kind of platform. Finally the help view which should contain the documentations for user to read is not currently working.

VIII. References a.http://www.eclipse.org b. http://java.sun.com/j2se/1.5.0/download.jsp c.http://www.cs.princeton.edu/~appel/modern/java/JLex d. http://cscope.sourceforge.net e.http://www.w3c.org/xml IX. Appendix a.Tools used i. eclipse ii. java iii. JLex iv. YACC v. XML b. Function API i. public static java.lang.Object[] doLex(java.lang.String inputFile) prints out the lexical file Parameters: inputFile - file to read Returns: an object array containing the information for the stack, symbolTable, symbol, constant, constantTable in array format. ii. public static void codeGeneration(java.lang.String InputFile) Parameters: InputFile - the file being read iii. public static void createErrorList() creates the error list iv. public static void init() initialze dialog. v. public static void decrypt(java.lang.String decryptfile, java.lang.String decryptCode) Parameters: decryptfile - the file to decrypt and decryptCode - the code for decryption vi. public static java.lang.String readFile(java.lang.String fileName) reads the entire file called fileName where "fileName" Parameters: fileName - file to be read. Returns: the file in String format. vii. public static java.lang.String readAtLine(java.lang.String fileName, int linenumber) Parameters: fileName - String name of file. linenumber - int line number to read. Returns: String of the linenumber.

X. Installation Instruction.

First go to http://download.eclipse.org/downloads/drops/S-3.1M3- 200411050810//download.php?dropFile=eclipse-SDK-3.1M3-win32.zip and download Eclipse 3.1 m3 build. Unzip them into any folder you want. It should create a folder called “eclipse”.

Second. Unzip cs491bplugin, cs491b, helloworldproject and helloworld zip file into the “eclipse” folder that was created.

Third: If you have JRE install you can start using the program. If not then do this.

A. Go to file, import project. Find the folder called “chuntext” inside the “eclipse” directory, not the one inside the plugin folder, that one should be name chuntext_3.0.2, and then repeat for “chunjob”, “chunproduct”, “helloworld”.

B. Next go to File, open perspective, when given a choice, select other. After that, select the plugin development option.

C. After go to run menu and select run. 1. In the perspective option pane set both the run and debug to be plugin development. 2. Click new launch configuration and select launch with all workspace and plugin, in the plugin tab. 3. Click on apply and run it. (You can now test the workbench).

Recommended publications