• Ingen resultater fundet

Development Process

In document Translation of a Subset of RSL into Java (Sider 123-127)

The translation module of the translator is developed using a full bootstrap-ping process. This means that the translator will be developed stepwise.

This section gives an overview of the steps and components involved in the bootstrapping process in the development of the translator. The translator is divided into three modules. Each module takes care of one stage in the trans-lation process. The steps and modules will be illustrated using tombstone diagrams.

The development of the translator from RSL into Java source code as-sumes that there is a compiler from Java to Java byte code and an interpreter for the machine used available, i.e. it assumes that J2SE SDK is available for the platform. The translation from Java into Java byte code and interpreta-tion of the byte code on the machine has been omitted from the diagrams.

When a program or a translator has Java as implementation language it is assumed to be executable in this context.

The first step is to develop a translator which translates a small subset of RSL into Java. Figure 3.23 illustrates the use of ANTLR to create a trans-Figure 3.23 Using ANTLR.

RSL0 RSLAST0

Java ANTLR

SPEC

lator translating from RSL0 to RSLAST0, which is the AST representation of RSL0.

Figure 3.24 Front end: Tool translating from RSL0 to RSLAST0.

RSL0 RSLAST0

Java

Figure 3.24 illustrates the result of using ANTLR on a specification of the syntax of RSL0, i.e. the front end of the translator.

Figure 3.25 Translation Module: Tool translating from RSLAST0 to JavaAst.

RSLAST0 JavaAST

Java

Figure 3.25 illustrates the translation module implemented by hand, which translates between the two abstract representations of the languages.

Figure 3.26 Back end: Tool for generating Java from the JavaAst.

JavaAST Java

Java

Figure 3.26 illustrates the module implemented by hand, which translates from the Java AST into Java source code, i.e., the back end of the translator.

These three modules can be combined into a three–stage translator. The flow of a program being translated is shown in Figure 3.27.

Figure 3.27 Combining the parts to a translator from RSL0 to Java.

P

RSL0

P

RSLAST0

P

JavaAST

P

RSL0 RSLAST0 Java

Java

RSLAST0 JavaAST

Java

JavaAST Java

Java

Figure 3.28 Result of combining the parts.

RSL0 Java

Java

The three–stage translator can be viewed as one translator from RSL0 to Java source code, as shown in Figure 3.28. This concludes the first step of the bootstrapping process. The result of this step is, as shown, a transla-tor translating from RSL0 into Java where each module is implemented by hand. This version of the translator is referred to as the “first version of the translator”.

The second step of the bootstrapping process is to create a specification of a translation module from RSLAST1 into JavaAST using RSL0 as im-plementation language. The new module is shown in Figure 3.29, and the specification in RSL may be found in appendix C.1.1. Furthermore, the RSL AST must be modified to integrate with the new version of the translation module. At this point the RSLAST1 could be extended to the full RSL lan-guage to avoid having to change it further in the next step. This was not done in this project, but it is suggested as the first point of an extension to this project in Chapter 7.

The translation module specified is made executable by first translating the specification developed using the translator developed in the first step.

The translation is shown in Figure 3.30. This results in a new translation module translating from RSLAST1 to JavaAST.

The new translation module is then combined with the modified front end and the back end into a new three–stage translator translating from RSL1

into Java source code, as shown in Figure 3.31.

The new three–stage translator can be viewed as one translating from

Figure 3.29 Specification of a new translation module.

RSLAST1 JavaAST

RSL0

Figure 3.30Translating the specification using the first version of the trans-lator.

RSL0 Java

Java

RSLAST1 JavaAST

RSL0

RSLAST1 JavaAST

Java

Figure 3.31Combining the new translation module with the front end and back end.

P

RSL1

P

RSLAST1

P

JavaAST

P

RSL1 RSLAST1 Java

Java

RSLAST1 JavaAST

Java

JavaAST Java

Java

RSL1 to Java implemented in Java, see Figure 3.32.

Figure 3.32 Result of combining the new parts.

RSL1 Java

Java

This concludes the second step of the bootstrapping process. The result is

a new translator which handles a slightly larger subset of RSL. This version of the translator is referred to as “the second version of the translator”.

The front end and the back end is only modified slightly by hand to fit the new constructs. The conclusion is that only a few modifications in Java are needed, while the main work in this step is done in RSL.

At this point, one can keep expanding and optimizing the translation module by specifying the new version in RSLn−1. The specification can then be translated using the three–stage translator of the previous step. The translated specification can then be combined with the front end and the back end into a new three–stage translator translating from RSLn to Java source code.

In document Translation of a Subset of RSL into Java (Sider 123-127)