progs/bf/bfc0.scala
changeset 738 084e2843f478
parent 736 d3e477fe6c66
equal deleted inserted replaced
737:14a348d050b3 738:084e2843f478
     1 // A Transpiler for the Brainf*** language
     1 // A Transpiler for the Brainf*** language to C
     2 //=========================================
     2 //===============================================
       
     3 //
       
     4 // Call with
       
     5 //
       
     6 //  amm bfc0.sc <<bf_program.bf>>
       
     7 //
     3 
     8 
     4 import io.Source
     9 
     5 import scala.util._
    10 import scala.util._
     6 
    11 
     7 
    12 
     8 // loding a bf-file 
    13 // loding a bf-file 
     9 def load_bff(name: String) : String = 
    14 def load_bff(name: String) : String = 
    62   for (i <- 0 until n) code
    67   for (i <- 0 until n) code
    63   val end = System.nanoTime()
    68   val end = System.nanoTime()
    64   (end - start)/(n * 1.0e9)
    69   (end - start)/(n * 1.0e9)
    65 }
    70 }
    66 
    71 
    67 // the mandelbrot program
    72 // Running Testcases
    68 val b0 = load_bff("mandelbrot.bf")
    73 //===================
    69 
    74 
    70 println(s"${time_needed(1, compile_run(b0))} secs")
    75 @doc(" the argument should be a BF program ")
       
    76 @main
       
    77 def main(fname: String) = {
       
    78   val bf_str = os.read(os.pwd / fname)
       
    79   println(s"${time_needed(1, run(bf_str))} secs")
       
    80 }  
    71 
    81 
    72 
    82 
    73 
    83 
    74 // a benchmark program (counts down from 'Z' to 'A')
       
    75 val b1 = """>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
       
    76             [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
       
    77             ++++++++[>++++++++++[>++++++++++[>++++++++++[>+
       
    78             +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++."""
       
    79 
       
    80 println(s"${time_needed(1, compile_run(b1))} secs")
       
    81 
       
    82 
       
    83 
       
    84