Download presentation

Presentation is loading. Please wait.

Published byVanessa Snyder Modified over 2 years ago

1
1 The TXL Programming Language (3) Mariano Ceccato FBK Fondazione Bruno Kessler

2
2 Rules and functions function 2To42 replace [number] 2 by 42 end function rule 2To42 replace [number] 2 by 42 end rule > > > Rules search the pattern!

3
3 Searching functions function 2To42 replace * [number] 2 by 42 end function Note: change only * > >

4
4 Deconstruct and searching functions rule vectorizeScalarAssignments replace [repeat statement] C1 [statement] C2 [statement] rest [repeat statement] deconstruct C1 V1 [var] := E1 [expr]; deconstruct C2 V2 [var] := E2 [expr]; where not E2 [reference V1] where not E1 [reference V2] construct Passign [statement] := ; by Passign rest end rule function reference V [variable] match * [variable] V end function Example: x:=x+1; y:=t+4; := ; x:=x+1; y:=x+4; No!

5
5 Extreme programming and TXL Txl is ideally suited to extreme programming (XP). Begin with an explicit set of testcases, and treat these as the specification of your transformation. Program your transformation incrementally, as a sequence of successive approximations to the final result. Actually run your partial transforms against the testcases to keep track of your progress and test as you go. Always write the simplest possible transformation rules to achieve the result. Begin each rule with an explicit example pattern and replacement, and generalize from there.

6
6 Example: XP and TXL (1) Step 1 – start with an explicit concrete example case. rule convertAddIJK replace [statement] add I to J giving K % COBOL by K = I + J; % PL/I end rule Step 2 – generalize by introducing pattern variables. rule convertAddGiving replace [statement] add I [Var] to J [Var] giving K [Var] by K = I + J; end rule N.B. Test at every stage

7
7 Example: XP and TXL (2) Step 3 – Add new cases. rule convertAddNoGiving replace [statement] add I [Var] to J [Var] by J = I + J; end rule Step 4 – Integrate different cases. rule convertAdds replace [statement] AddStatement [cobol_add_statement] by AddStatement [convertAddNoGiving] [convertAddGiving] end rule N.B. Test at every stage

8
8 Exercises - Add to the commands language: 1)If cond then statements endIf 2)Case cond1->statement1 … condN->statementN endCase - Transform a list of contiguos if-statements in a case- statement If x>1 then x:=x+1 endIf If x=1 then x=0 endIf If x<1 then x:=x-1 endIf case x>1 -> x:=x+1; x=1 -> x=0; x x:=x-1; end case

9
9 Homework - Reading The Guided Tour (website - Transform a case-statement in a list of contiguos if-statements. case x>1 -> x:=x+1; x=1 -> x=0; x x:=x-1; end case If x>1 then x:=x+1 endIf If x=1 then x=0 endIf If x<1 then x:=x-1 endIf

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google