Method and apparatus for translating source code from one high-level computer language to another
First Claim
1. A method for use in a computer system for translating a first source code of a source computer language into a second source code of a target computer language, said method comprising:
- creating a source doubly-rooted tree data structure, said creating including;
retrieving the first source code;
producing virtual source from the first source code to create a source fragment tree;
scanning the first source code to form a virtual source;
identifying the virtual source as leaves of the source doubly-rooted tree;
identifying leaves of the source fragment tree with the leaves of the source doubly-rooted tree;
parsing the virtual source into a source syntax tree such that the leaves of the source syntax tree are identified with the leaves of the source doubly-rooted tree; and
obtaining and storing semantic information completing a description of the source code in the source syntax tree;
creating a target doubly-rooted tree data structure including;
translating the source syntax tree and creating a target syntax tree;
identifying leaves of the target syntax tree with leaves of the target doubly-rooted tree;
associating leaves of the target doubly-rooted tree with corresponding leaves of the source doubly-rooted tree;
translating the source fragment tree and creating a target fragment tree so that leaves of the target fragment tree are ordered; and
identifying leaves of the target fragment tree with leaves of the target doubly-rooted tree;
generating the second source code from the target doubly-rooted tree; and
storing the second source code.
4 Assignments
0 Petitions
Accused Products
Abstract
A method, system, apparatus, and program for translating one computer language to another using doubly-rooted tree data structures. A doubly-rooted tree is the combination of two sets of hierarchically related objects sharing a common set of leaves. An N-rooted tree is also described. When a doubly-rooted tree is constructed in the specified manner and then translated to a second doubly-rooted tree, source language code is transformed into target language code. In addition, the translation preserves preprocessor characteristics of the source language code including macros, conditionally compiled regions of code, source inclusion statements, and comments.
-
Citations
3 Claims
-
1. A method for use in a computer system for translating a first source code of a source computer language into a second source code of a target computer language, said method comprising:
-
creating a source doubly-rooted tree data structure, said creating including; retrieving the first source code; producing virtual source from the first source code to create a source fragment tree; scanning the first source code to form a virtual source; identifying the virtual source as leaves of the source doubly-rooted tree; identifying leaves of the source fragment tree with the leaves of the source doubly-rooted tree; parsing the virtual source into a source syntax tree such that the leaves of the source syntax tree are identified with the leaves of the source doubly-rooted tree; and obtaining and storing semantic information completing a description of the source code in the source syntax tree; creating a target doubly-rooted tree data structure including; translating the source syntax tree and creating a target syntax tree; identifying leaves of the target syntax tree with leaves of the target doubly-rooted tree; associating leaves of the target doubly-rooted tree with corresponding leaves of the source doubly-rooted tree; translating the source fragment tree and creating a target fragment tree so that leaves of the target fragment tree are ordered; and identifying leaves of the target fragment tree with leaves of the target doubly-rooted tree; generating the second source code from the target doubly-rooted tree; and storing the second source code. - View Dependent Claims (2)
-
-
3. An apparatus for translating a first source code of a source computer language into a second source code of a target computer language while preserving text preprocessor statements and expressions comprising:
-
source computer language file means with memory allocated for storing the first source code; target computer language file means with memory allocated for storing the second source code; means for creating a first and second doubly-rooted tree data structures with memory allocated for information to be stored within the first and second data structures; means for retrieving the first source code from memory; means for scanning and parsing the first source code into a first virtual source; means coupled to the scanning and parsing means for storing the first virtual source code while scanning and parsing in the first doubly-rooted tree data structure so that text preprocessor statements and expressions are preserved; means for translating the first doubly-rooted tree structure into a second virtual source code; means coupled to the translating means for storing the second virtual source code in the second doubly-rooted tree data structure so that text preprocessor statements and expressions are preserved; means for traversing the second data structure coupled to means for creating the second source code; means for storing the second source code coupled to the target computer language file means.
-
Specification