A Brief Stratego/XT TutorialKarl Trygve KallebergEelco VisserDagstuhl Workshop: Beyond Program Slicing, 7.-11. Nov 2005Plan of AttackI Explain the basics of StrategoI Terms, signatures, rewrite rules, strategies, concrete syntax,dynamic rulesI Motivate with a small case-studyI Constant propagationI Give a tiny tool demoI Take questionsOutline1 Motivation2 Terms and Signatures3 Transformation Rules4 Transfo Strategies5 Dynamic RulesPart IMotivationfor i := 1 to n dofor j := 1 to n doc[i,j] := let var d := 0in for k := 1 to n dod := d + a[i,k] * b[k,j];dendlet var din for i := 1 to n dofor j := 1 to n do(d := 0;for k := 1 to n do d := d + a[i,k] * b[k,j];c[i,j] := d)endExample: Desugaringfor i := 1 to n dofor j := 1 to n doc[i,j] := sum k = 1 to n (a[i,k] * b[k,j])let var din for i := 1 to n dofor j := 1 to n do(d := 0;for k := 1 to n do d := d + a[i,k] * b[k,j];c[i,j] := d)endExample: Desugaringfor i := 1 to n dofor j := 1 to n doc[i,j] := sum k = 1 to n (a[i,k] * b[k,j])for i := 1 to n dofor j := 1 to n doc[i,j] := let var d := 0in for k := 1 to n dod := d + a[i,k] * b[k,j];dendExample: Desugaringfor i := 1 to n dofor j := 1 to n doc[i,j] := sum k = 1 to n (a[i,k] * b[k,j])for i := 1 to n dofor j := 1 to n doc[i,j] := let var d := 0in for k := 1 to n dod := d + a[i,k] * b[k,j];dendlet var din for i := 1 to n dofor j := 1 to n do(d := 0;for k := 1 to n do d := d + a[i,k] * b[k,j];c[i,j] := d)endThe ...
Explain the basics of Stratego ITerms,signatures,rewrite rules,strategies,concrete syntax, dynamic rules Motivate with a small case-study IConstant propagation
for i := 1 to n do for j := 1 to n do c[i,j] :=sum k = 1 to n (a[i,k] * b[k,j])
for i := 1 to n do for j := 1 to n do c[i,j] :=let var d := 0 in for k := 1 to n do d := d + a[i,k] * b[k,j]; d end
let var d infor i := 1 to n do for j := 1 to n do (d := 0; for k := 1 to n do d := d + a[i,k] * b[k,j]; c[i,j] :=d)
end
TheBigPicture
A Simple Pipeline
1
2
3
4
5
Source code isparsedinto astructuredrepresentation, a concrete syntax tree(CST).
The CST is pruned for non-essential information, to yield abstract syntax tree(AST).
Additional information is added, e.g. type information.
One or multipletransformationsare applied to the AST.
The result is serialized back to file.
an
hTeSmalliPtcuer
Thesyntax definitiondeclares programs we transform and is stages.
thestructureof the used in constructing
language for the most pipeline
Terms
Part
and
I
I
Signatures
Tersm
ITerms are astructured representationof programs. ITheir structure is often derived from the syntax definition of the language. IThe syntax definition gives rules for the structural validation of terms.
Terms are primarily used to encodeabstract syntax trees.