 The Gentle Compiler Construction System

# Gentle Concepts

Gentle
Applications
Concepts
Examples
Handbook
Support Originally designed in 1989 at the GMD Karlsruhe Lab, the Gentle Compiler Construction System pioneered the notion of term types, pattern matching, and rule-based programming for compiler construction. Gentle served as model for other successful systems. Gentle is the first compiler construction system that handles the full spectrum from analysis over transformation to synthesis. Instead of confronting the user with a bunch of special purpose languages Gentle provides a uniform notation for all tasks. Gentle is based on recursive definition and structural induction: the underlying paradigms of virtually all tasks of translation. Gentle allows the user to define mutally recursive types by enumerating alternative structures ``` Expr = plus(Expr,Expr), minus(Expr,Expr), const(INT) ``` Programs in Gentle are expressed by rules of the form ``` G : A B C ``` These rules may be interpreted as grammar rules (G is constructed from A, B, and C), as logical statements (G is true if A, B, and C are true), or in a procedural way (to solve task G solve subtasks A, B, and C). Members of a rule may have parameters (an arrow separates input from output parameters). This results in attributed grammars ``` AddingExpression(-> plus(X1, X2)): AddingExpression(-> X1) "+" Primary(-> X2) ``` or in transformation schemes that inductively follow the structure of terms ``` Eval(plus (X1, X2) -> N1+N2): Eval(X1 -> N1) Eval(X2 -> N2). Eval(minus(X1, X2) -> N1-N2): Eval(X1 -> N1) Eval(X2 -> N2). Eval(const(N) -> N). ``` Unparsing may be expressed in a similar way ``` Code(plus(X1, X2) -> Reg2) : Code(X1 -> Reg1) Code(X2 -> Reg2) Emit("add", Reg1, Reg2) ``` Such rules can be augmented with cost values. Then rules are selected in such a way that the sum of the costs of all selected rules is optimal. The rule-based approach follows the principle of locality: Complex interactions are avoided and a system can be understood by understanding small pieces in isolation. You describe individual constructs independently. The paradigm leads to a data-oriented methodology: The structure of data is mirrored by the structure of algorithms. This methodology turns out to be a strong guideline in compiler projects.