module til-desugar imports TIL rules ForToWhile : For(x, e1, e2, st*) -> Block([ DeclarationTyped(y, TypeName("int")), Assign(x, e1), Assign(y, e2), While(Leq(Var(x), Var(y)), (st*, [Assign(x, Add(Var(x), Int("1")))]) ) ]) where new => y IfThenToIfElse : IfThen(e, st*) -> IfElse(e, st*, []) DefaultDeclaration : Declaration(x) -> DeclarationTyped(x, TypeName("int")) WriteInt : ProcCall("writeint", [e]) -> ProcCall("write", [FunCall("int2string", [e])]) ReadInt : FunCall("readint", []) -> FunCall("string2int", [FunCall("read", [])]) BinOpToFunCall : op#([e1,e2]){t*} -> FunCall(op, [e1,e2]){t*} where op FunCallToBinOp : FunCall(op, [e1,e2]){t*} -> op#([e1,e2]){t*} where op is-bin-op = "Add" <+ "Mul" <+ "Subt" <+ "Div" <+ "Mod" <+ "Geq" <+ "Leq" <+ "Gt" <+ "Lt" <+ "Equ" <+ "Neq"