Talk:Maentwrog

From Esolang
Jump to navigation Jump to search

This language can actually emulate brainfuck without input

Here is how. The following code assumes long is 4-byte.

  1. Execute this at first: : initialize 30000 4 * alloc *arr =arr *ptr 0 =ptr ; initialize.
  2. Then this: : init-arr 0 arr ptr + set + 1 =ptr ptr 30000 > @init-arr ; 0 init-arr 0 =ptr
  3. Each non-looping commands can be translated into these:
    • >: : go-right ptr 4 + =ptr ;
    • <: : go-left 4 ptr - =ptr ;
    • +: : increment arr ptr + get 1 + 256 swap mod arr ptr + swap put ;
    • -: : decrement 1 arr ptr + get - 256 swap mod arr ptr + swap put ;
    • .: : output arr ptr + get .. ;
  4. Looping commands [ and ].
    • For example if your code was: +++[>++<-]>., then translate into this:
rem put here what 1. and 2. says. ;
rem put non-looping words definitions ;

rem loop1 is for >++<- ;
: loop1
   rem translated from >++<- ;
      go-right inc inc go-left dec 
   rem here is to check if zero or not. ;
      arr ptr + get @loop1 ;

rem this is for +++ ;
   inc inc inc

rem this is for [>++<-] ;
   arr ptr + get @loop1

rem this is for >. ;
   go-left output

rem this is to free array ;
   arr free

No matter how many nested loops your BF has, your BF programs should be translated into Maentwrog, like the example above says.

--YamTokTpaFa (talk) 13:33, 17 May 2020 (UTC)