How to resolve the algorithm Execute Brain step by step in the M2000 Interpreter programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Execute Brain step by step in the M2000 Interpreter programming language

Table of Contents

Problem Statement

RCBF is a set of Brainf*** compilers and interpreters written for Rosetta Code in a variety of languages. Below are links to each of the versions of RCBF. An implementation need only properly implement the following instructions: Any cell size is allowed,   EOF   (End-O-File)   support is optional, as is whether you have bounded or unbounded memory.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Execute Brain step by step in the M2000 Interpreter programming language

Source code in the brainfuc programming language

Module Checkit {
      \\ Brain**** Compiler
      
      Escape Off
      \\ no Esc function so we can use Ctrl+Z when input characters to terminate BF
      \\ ctrl+c open dialog for exit - by default in console mode
      
      Const skipmonitor as boolean=true, output as boolean=True
      Const ob$="{",cb$="}"
      Gosub CallOne
      \\ We use a group object with events.
      
      Group WithEvents BF=BrainF()
      
      Function BF_monitor {
            \\ Event functions have same scope as the module where belong
            If skipmonitor Then exit
            Read New pc, mem
            Print pc, mem
            Print "Press space bar": While Key$<>" " {}
      }
      Function BF_newline {
            If not skipmonitor then Print "newline" : exit
            if output then Print
      }
      Function BF_print {
            Read New c$
            If not skipmonitor then Print "character:";c$  : exit
            if output then Print c$;
      }
      
      Program$ = {++++++[>++++++++++++<-]>.
                  >++++++++++[>++++++++++<-]>+.
                  +++++++..+++.>++++[>+++++++++++<-]>.
                  <+++[>----<-]>.<<<<<+++[>+++++<-]>.
                  >>.+++.------.--------.>>+.
                  }
      Report Program$
      ExecBF(Program$)
      End
      
      Sub ExecBF(Code$)
            ClearMem()
            code$=filter$(code$, " "+chr$(10)+chr$(13))
            code$<=replace$(".","@", code$)
            code$<=replace$("-","-.D()", code$)
            code$<=replace$("+","-.A()", code$)
            code$<=replace$("<","-.L()", code$)
            code$<=replace$(">","-.R()", code$)
            code$<=replace$("@","-.P()", code$)
            code$<=replace$("[","-.S("+ob$,code$)
            code$<=replace$("]",cb$+")",code$)
            code$<=replace$(",","-.K()", code$)
            Rem : Print code$
            BF.Eval code$
            Print
      End Sub
      Sub ClearMem()
            Dim cMem(1 to 30000)=0
            For BF {
                  .Pc=1
                  .Zero=True
                  .Mem()=cMem()
            }
      End Sub
      CallOne:
      Class BrainF {
            events "monitor", "newline", "print"
            Dim Mem()
            Pc=1, Zero as Boolean=True
            Module UpdateZero {
                  .Zero<=.Mem(.Pc)=0
                  call event "monitor", .pc, .Mem(.pc)
            }
            Function A {   \\ +
                  .Mem(.Pc)++ 
                  .UpdateZero
            }
            Function D {  \\ -
                  .Mem(.Pc)-- 
                  .UpdateZero
            }
            Function R { \\ >
                  If .Pc=30000 Then Error "Upper Bound Error"
                  .Pc++
                  .UpdateZero
            }
            Function L { \\ <
                  If .Pc=1 Then Error "Lower Bound Error"
                  .Pc--
                  .UpdateZero
            }
            Function P { \\ .
                  Select Case .Mem(.Pc)
                  Case >31
                        Call Event "print", Chr$(.Mem(.Pc))
                  Case 10
                        Call Event "newline"
                  End Select
            }
            Function K {  \\ ,
                  .Mem(.Pc)=Asc(Key$)
                  \\ ctrl+z for exit
                  If .Mem(.Pc)=26 Then  Error "Finished"
                   .UpdateZero
            }
            Function S  { \\ [  
                  If .Zero then =0: exit
                  Read newEval$
                  Do {ret=Eval(newEval$)} until .Zero
            }
            Module Eval {
                  ret=eval(Letter$)
            }
      }
      Return
}
Checkit

  

You may also check:How to resolve the algorithm Parametric polymorphism step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Pythagorean triples step by step in the Action! programming language
You may also check:How to resolve the algorithm Kolakoski sequence step by step in the C programming language
You may also check:How to resolve the algorithm Bitwise operations step by step in the OpenEdge/Progress programming language
You may also check:How to resolve the algorithm Tau function step by step in the Haskell programming language