A Language Translator Generator for Extending C++

Frequently, conventional extensions for a strongly typed, object-oriented language have been done by directly modifying the base language system. One drawback of this method, however, is that at the start of a system-specific language design, the specifications of language are not usually clear, and therefore, must be decided experimentally. Furthermore, in a practical language extension, it is necessary to handle several libraries provided for supporting various aspects of a system. Consequently, it is necessary to design a simple method of extending a language.

OPTEC is a language translator generator for extending C++. The purpose of OPTEC is to facilitate the construction of a system-specific language for each system architecture and associated class libraries. OPTEC automatically generates a language translator from a specification of the extension. To simplify specification of the translation, a tree rewriting method is adopted, in which a syntax tree for the source code is converted by transformation rules. The language translator converts a source code, using extended C++, into a non-extended C++ code. The reason for choosing C++ as a base language is that many programmers are familiar with C language; from which C++ was derived.

Figure [*] illustrates the software organization of the OPTEC system. Language extension definitions are described separately with 2 source files. One is for syntax extension definition, and the other is for transformation rules. A translator is constructed as follows: First, the parser generator creates a YACC source with a syntax extension definition and a YACC template file, in which C++ syntax is defined. The parser generator also creates a parser for rule descriptions. Then, transformation rules are processed with default rules, and the C++ program for the tree transformer is generated. During this process, the template pattern and the semantic predicates of the rules are preprocessed by the pattern compiler for making later rule selection efficient.

Figure: Organization of OPTEC system
\begin{figure*}\leavevmode\hbox{\epsfbox{kojima-fig1.ps}}\end{figure*}