progs/compile.scala
changeset 625 6709fa87410b
parent 624 8d0af38389bc
child 668 9ce78065f68d
equal deleted inserted replaced
624:8d0af38389bc 625:6709fa87410b
   255   List(Assign("n", Num(10)),            //  n := 10;                     
   255   List(Assign("n", Num(10)),            //  n := 10;                     
   256        Assign("minus1",Num(0)),         //  minus1 := 0;
   256        Assign("minus1",Num(0)),         //  minus1 := 0;
   257        Assign("minus2",Num(1)),         //  minus2 := 1;
   257        Assign("minus2",Num(1)),         //  minus2 := 1;
   258        Assign("temp",Num(0)),           //  temp := 0;
   258        Assign("temp",Num(0)),           //  temp := 0;
   259        While(Bop("<",Num(0),Var("n")),  //  while n > 0 do  {
   259        While(Bop("<",Num(0),Var("n")),  //  while n > 0 do  {
   260           List(Assign("temp",Var("minus2")),    //  temp := minus2;
   260           List(Assign("temp",Var("minus2")), //  temp := minus2;
   261                Assign("minus2",Aop("+",Var("minus1"),Var("minus2"))), 
   261                Assign("minus2",Aop("+",Var("minus1"),Var("minus2"))), 
   262                                         //  minus2 := minus1 + minus2;
   262                                         //  minus2 := minus1 + minus2;
   263                Assign("minus1",Var("temp")), //  minus1 := temp;
   263                Assign("minus1",Var("temp")), //  minus1 := temp;
   264                Assign("n",Aop("-",Var("n"),Num(1))))), //  n := n - 1 };
   264                Assign("n",Aop("-",Var("n"),Num(1))))), //  n := n - 1 };
   265        Write("minus1"))                 //  write minus1
   265        Write("minus1"))                 //  write minus1