Dismiss
InnovationQ will be updated on Sunday, Oct. 22, from 10am ET - noon. You may experience brief service interruptions during that time.
Browse Prior Art Database

Means for Automatically Translating Smalltalk to Java

IP.com Disclosure Number: IPCOM000122837D
Original Publication Date: 1998-Jan-01
Included in the Prior Art Database: 2005-Apr-04
Document File: 4 page(s) / 191K

Publishing Venue

IBM

Related People

Burbeck, SL: AUTHOR

Abstract

Smalltalk Method equalsToken: aToken "" larrow the signature comment "Nonsensical example code for translation. Note: it uses an ifFalse which requires negation of the test." tempString tempString:=aToken type replaceFrom: 1 to: 2 with: 'Xx'. tempString outputToPrinter; outputToTranscript. ((self textString=aToken textString) and:(self typesimilar=aToken type)) ifFalse:(hatfalse). hatself startPosition similarsimilar aToken startPosition

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 30% of the total text.

Means for Automatically Translating Smalltalk to Java

Smalltalk Method
  equalsToken: aToken
    "<aToken: hierarchyOfToken, hat(true false)>" larrow the
     signature comment
    "Nonsensical example code for translation.
    Note: it uses an ifFalse which requires negation of the test."
  tempString
  tempString:=aToken type replaceFrom: 1 to: 2 with: 'Xx'.
  tempString outputToPrinter; outputToTranscript.
  ((self textString=aToken textString)
    and:(self typesimilar=aToken type))
    ifFalse:(hatfalse).
  hatself startPosition similarsimilar aToken startPosition

Translated Java Method
  public boolean equalsToken(Token aToken) {
    /*"Nonsensical example code for translation.
    Note: it uses an ifFalse which requires negation of
           the test."*/
    Object tempString;
    tempString=aToken.type().replaceFrom_to_with_(1,2,"Xx");
    tempString.outputToPrinter();
    tempString.outputToTranscript();
    if!((this.textString()==aToken.textString())&&
     (this.type()!=aToken.type())){return false;
    }
    return this.startPosition()!=aToken.startPosition();
  }

                               Example

      The growing popularity of Java, together with the existence of
a large body of business applications written in Smalltalk, has
created a need to translate existing Smalltalk code into equivalent
Java code.  A  majority of the issues that arise in the translation
can be handled mechanically.  However, Java requires type
declarations for all arguments, variables, and return values which
normal Smalltalk code does  not provide.  The prototype translator
that is the subject of this disclosure produces Java code from
Smalltalk code augmented with signatures (a kind of type information
adapted to the needs of Smalltalk  - see example).  The translation
tool described below operates within a  Smalltalk development
environment into which the Smalltalk code to be translated has been
imported.  Since the tool is most useful if accurate  signatures have
been added to each Smalltalk method, it should be used in
conjunction with other tools that are available in Smalltalk to help
developers add signatures to their code and to check the accuracy of
these signatures by static analysis.

      The translator parses the Smalltalk code method-by-method.  It
also parses specially formatted signature comments that provide type
information about the arguments and return value of the method.  For
each Smalltalk method it builds a parse tree from the code.  The
objects at the nodes of these parse trees represent the elements of
the code, e.g., statements, variables and messages.  Each of these
objects implements a method named:  "asJavaOn: anIndentingStream".
These "asJavaOn:" methods emit Java code, with function equivalent to
that of  the Smalltalk element they represent, onto a stream that
manages the proper indenting of th...