Download Abstract - Robert Chatley
Transcript
Translation A large part of the work in developing the Kenya system was developing a way to translate Kenya code into Java code. Although this is a mechanical translation, I wanted the Java code that was produced to look as "human generated" as possible. It should be as close as possible to the code that a human programmer would write to solve the problem in Java. There should perhaps be a caveat here. Java is an object-oriented language, and the way in which "good" (or certainly large) programs are written in Java normally makes much use of this. Kenya is not an object-oriented language. There is provision for defining classes and creating instances of these classes, but there is no inheritance, and therefore no type polymorphism. (As it happens, this is the same as Visual Basic, which Microsoft claims is object-oriented, but I would argue against this). It is suggested that novice programmers should not be introduced immediately to the object-oriented programming paradigm, but that they should begin with a more traditional, structured approach. Because of this, the Kenya system will generate the Java code that a programmer would write to solve a problem if they were approaching it in a structured way, rather than an object-oriented way. There is not a straightforward mapping between a structured program and an object-oriented program to solve the same problem, as they are two different ways of thinking about solving the problem. This makes the task of writing a mechanical translator from structured code to object-oriented code extremely difficult. It also means that, were such a translation achievable, a novice programmer looking at the generated code would not easily be able to see, based on the way that they had been thinking about the problem, how the Java code worked. To carry out the translation, first the text representing the Kenya program must be processed to form an abstract representation. Then the abstract representation can be processed, generating the relevant Java code from each construct and expression in the program. Parsing The parser for Kenya was generated using SableCC[12], as it outputs Java code which is easy to incorporate with the rest of the code for the project. Also, the use of the Visitor pattern allows for easy extension of the functionality defined over the AST without having to modify any of the generated code by hand, and also leads to an elegant solution. 37