main_marking5/bf.scala
changeset 463 0315d9983cd0
parent 424 daf561a83ba6
--- a/main_marking5/bf.scala	Sun Jan 15 10:58:13 2023 +0000
+++ b/main_marking5/bf.scala	Sat Mar 11 22:01:53 2023 +0000
@@ -111,7 +111,12 @@
 def run(prog: String, m: Mem = Map()) = compute(prog, 0, 0, m)
 
 
+def generate(msg: List[Char]) : String = msg match {
+  case Nil => ""
+  case c::cs => s"${"+" * c.toInt}.[-]" ++ generate(cs) 
+}
 
+//println(generate("Hello World\n".toList))
 
 
 // some sample bf/bf++-programs collected from the Internet
@@ -213,3 +218,6 @@
 
 //M5a.run(M5a.load_bff("mandelbrot.bf"))
 //M5a.run(M5a.load_bff("collatz.bf"))
+
+//println(M5a.generate("ABC".toList))
+//M5a.run(M5a.generate("Hello World\n".toList))
\ No newline at end of file