Software Design


The software designed in this project takes a Kenya program and processes it in several ways. It builds an abstract representation of the program which can be checked for correctness and translated to Java code to be compiled and run. The details of the different stages of processing are given in the following sections. This section describes the overall structure of the system and how the different parts fit together.

The flow of information through the system is shown in the figure below. A textual representation of the Kenya source code is typed by the user. This is transformed into an abstract syntax tree by a lexical analyser and a parser. The tree is processed by a type checker to ensure correctness of the program, and by a translator to produce Java source code. The Java source code is then saved in a file in a directory and the compiler is run to produce a class file.

data flow

Information flow through the Kenya system

In order to provide platform independence, the software developed in this project has been written in Java. The diagrams below show some of the more important classes and how they are linked together. All of the different functional parts of the system are linked together by the user interface. The rationale behind the design of the user interface is described in another section. The user can enter code into the text areas and invoke other functions by pressing the buttons on the toolbar. Each JButton has an ActionListener which listens for mouse clicks and then calls appropriate routines to parse the code, compile it, open a file etc.

overall structure

The overall structure of the user interface

When the ParseListener detects a mouse click on the "parse" button it creates a parser and a lexical analyser to construct an abstract syntax tree from the text in the KenyaArea. The tree is formed from instances of subclasses of the class Node. A TypeChecker object is then created and applied to the tree. The type checker maintains a set of known types and a symbol table mapping names to types.

typechecker classes

The classes related to the type checker

After the correctness of the program has been checked, a Translator object is created and used to process the tree to produce Java code. The translator adds each line of code that it generates to a Vector. Later the ParseListener can access the code using the translator's getCode() method. It writes each line of Java code into the JavaArea.

translator classes

The classes related to the translator

Compiling the code involves the system writing the contents of the JavaArea into a file. The compiler is then run in an external process and produces class files.

When executing a compiled program, the system again runs it in a separate process but connects to the standard input and output streams for this process. This is so that output from the program can be piped into a window inside the Kenya user interface, and input from the user can be fed back to the process to allow interactive programs to be written and tested.

External process

The classes related to executing a compiled program