The following paper was originally published in the Proceedings of the Conference on Domain-Specific Languages Santa Barbara, California, October 1997
KHEPERA: A System for Rapid Implementation of Domain Specific Languages
Rickard E. Faith, Lars S. Nyland, Jan F. Prins University of North Carolina, Chapel Hill
For more information about USENIX Association contact: 1. Phone: 510 528-8649 2. FAX: 510 548-5738 3. Email: [email protected] 4. WWW URL:http://www.usenix.org
Khepera: A System for Rapid Implementation of Domain Sp eci c
Languages
Rickard E. Faith Lars S. Nyland Jan F. Prins
Department of Computer Science
University of North Carolina
CB 3175, Sitterson Hal l
Chapel Hil l NC 27599-3175
ffaith,nyland,[email protected]
Abstract ample a C compiler is attractive b ecause it pro-
vides p ortabilityover a large class of architectures,
while achieving p erformance through the near uni-
The Khepera system is a to olkit for the rapid im-
versal availability of architecture-sp eci c optimizing
plementation and long-term maintenance of domain
C compilers.
sp eci c languages DSLs. Our viewp oint is that
Yet there are some drawbacks to this approach.
DSLs are most easily implemented via source-to-
While DSLs are often simpler than general purp ose
source translation from the DSL into another lan-
programming languages, the domain-sp eci c infor-
guage and that this translation should b e based on
mation available may result in a generated program
simple parsing, sophisticated tree-based analysis and
that can b e much larger and substantially di erent
manipulation, and source generation using pretty-
in structure than the original co de written in the
printing techniques. Khepera emphasizes the use
DSL. This can make debugging very dicult: an
of familiar, pre-existing to ols and provides supp ort
exception raised on some line of an incomprehensi-
for transformation replay and debugging for the DSL
ble C program generated by the DSL pro cessor is a
pro cessor and end-user programs. In this pap er, we
long way removed in abstraction from the DSL input
presentanoverview of our approach, including im-
program.
plementation details and a short example.
Since the DSL pro cessor is comp osed with a native
high-level compiler, and do es not have to p erform
machine-co de generation or optimization, we b elieve
1 Intro duction
that there are some basic di erences between the
construction of a compiler for a general purp ose pro-
gramming language and the construction of a trans-
Domain sp eci c languages DSL can often be im-
lator for a DSL. Our view is that DSL translation is
plemented as a source-to-source translator comp osed
most simply expressed as
with a pro cessor for another language. For example,
PIC [8], a classic \little language" for typ esetting
gures, is translated into troff, a general-purp ose
1. simple parsing of input into an abstract syntax
typ esetting language. Language comp osition can b e
tree ast,
extended in either direction: the CHEM language
2. translation via sophisticated tree-based analysis
[1], a DSL used for drawing chemical structures, is
and manipulation, and
translated into PIC, while troff is commonly trans-
lated into PostScript.
3. output source generation using versatile pretty-
Other DSLs translate into general-purp ose high-level
printing techniques.
programming languages. For example, ControlH, a
DSL for the domain of real-time Guidance, Naviga-
We add the additional caveat that the translation
tion, and Control GN&C software, translates into
pro cess retain enough information to supp ort the in-
Ada [5]; and Risla, a DSL for nancial engineering,
verse mapping problem, i.e., given a lo cus in the out-
translates into COBOL [18].
put source, determine the tree manipulations and in-
The comp osition of a DSL pro cessor with for ex- put source elements that are resp onsible for it. This