 |
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.
|