\\,\1 ) y \.J.' \ I) v\ t:X- l V\ , -'l.'"r /-i;b \..U,- r r- J ,V \ ' , ", I ..u '2 ... I'. e...' \'''' ::::'C,e.V'Le/ 'JO\.-.JM£.... ".;aO- Wfe,. t-..l<- T J ., l I __ _ _ _ " te. (; ",,,,,(I -.+t, -tf,,·'Slu tl;:;,·, Translating Between Programming Languages Using A Canonical Representation And Attribute Grammar Inversion Rodney Farrow and Daniel Yellin CoMp0 't I tJ 'I \ OOd-. -::r Extended Abstract Automatic translation between programming languages is an important tool for increasing program reusability. Often the need arises to transport a large software system from one source language environment to another. Performing such a translation by hand is a large undertaking. costly in manpower and very error-prone. For this reason, several researchers have built automated tools to aid them in particular such projects [3, 1]. In this paper we present a new methodology for building source-to-source translators. This methodology involves designing a canonical form to represent programs of all source languages involved, and using attribute grammars (AGs) and automatic AG-inversion to build bi- directional translators between the various source languages and the canonical form. To test the feasibility of these ideas, we have created a system to translate between the C and Pascal programming languages. The basic idea behind using AG inversion to translate between programming languages is illustrated by the diagram of figure 1. In this example we would like to translate between the four programming languages, A, B, C, and D. In order to do so, we flrst write four invertible AGs, T A' T E' T c> and T D' specifying the translation of each language into a canonical form. We then automtically invert these specifications, obtaining the inverse AGs TA-I, TB-I, TC- I , and T D- I , specifying the translation from the canonical form back to each programming language. By composing the translators obtained by this method we are able to produce a translator between any pair of languages. For example, the translator from language A to language D can be obtained by composing the specifications TD-I and T A' Similarly, its inverse, the translator from language D to language A, is obtained by forming the composition T A-loT D' For this method to succeed, we must have a canonical form in which all source language