Table of Contents
This chapter is work in progress. Not all parts have been finished yet. The latest revision of this manual may contain more material. Refer to the online version.
renaming of bound variables
Figure 4.1. file: til/renaming/til-rename-vars.str
module til-rename-vars imports TIL liblib strategies io-til-rename-vars = io-wrap(til-rename-vars) til-rename-vars = Var(RenameVar) <+ Assign(RenameVar, til-rename-vars) // <+ Read(RenameVar) <+ For(RenameVar, til-rename-vars, til-rename-vars, til-rename-vars) <+ RenameDeclaration <+ Block({| RenameVar : map(til-rename-vars) |}) <+ all(til-rename-vars) RenameDeclaration : Declaration(x) -> Declaration(y) where <newname> x => y ; rules( RenameVar : x -> y ) RenameDeclaration : DeclarationTyped(x, t) -> DeclarationTyped(y, t) where <newname> x => y ; rules( RenameVar : x -> y )
Figure 4.2. file: til/xmpl/rename-test
sglri -p ../syn/TIL.tbl -i test1.til |\ ../renaming/til-rename-vars |\ ast2text -p ../pp/TIL-pretty.pp -o test1.rn.txt
Table 4.1. files: til/xmpl/test1.til, til/xmpl/test1.rn.txt
before | after |
---|---|
// TIL program computing the factorial var n; n := readint(); var x; var fact; fact := 1; for x := 1 to n do fact := x * fact; end write("factorial of "); writeint(n); write(" is "); writeint(fact); write("\n"); | var n0; n0 := readint(); var x0; var fact0; fact0 := 1; for x0 := 1 to n0 do fact0 := x0 * fact0; end write("factorial of "); writeint(n0); write(" is "); writeint(fact0); write("\n"); |