MSFE++
Introduce&Syntax
It is an extended version of MiniStringFuck. Changed from only 2 operators to 3.We also added 2 bytes.Here are three operators in MSFE++.
+ operator: used to add one to the current byte.
- operator: new operator. Subtracts the current byte by 1 and moves to the next byte. If executed at the last byte, moves to the first byte.
Asterisk (*) operator: Iterates through the contents until the byte is 0. If a loop is nested within a loop, which level of the loop needs several asterisks to indicate it. e.g.:*+**+***++***+**+* (infinte loop, just like [+[+[++]+]+] in BrainFuck)
Three minuses will output the current byte. Four will input the current byte.
Computational class
Assuming that the program *a**b***c***b**a*
is equivalent to [a[b[c]b]a]
and there are a fixed, finite number of unbounded cells (as in the reference implementation), MSFE++ is Turing complete since ALWCIDFEC can be reduced to it.
A move right command can be achieved with +-
. A no-op can be achieved by using this as many times as there are cells. For the reference implementation, >>>
= +-+-+-
is the no-op. A move left is possible by using n-1 move rights, for n many cells, 2 for the reference implementation.
To ensure disambiguous parsing of loops, around each intended group of asterisks, a no-op is placed, e.g. for the intended behavior of [a[b[c]b]a]
_*_a_**_b_***_c_***_b_**_a*_
is used, where _
is the no-op. We can translate any bracketed loop to this scheme, and we can even use completely unique counts for different loops even if nesting was reduced to ensure disambiguous behavior.
We are also able to create a simple decrement by adding n-1 move rights after the decrement, where n is the number of cells, like ->>
for the reference implementation's 3 cells.
Since there is a move right, move left, decrement, increment, and conditional looping, MSFE++ is capable of implementing 3 cell Brainfuck/ALWCIDFEC, meaning it is Turing complete.
Examples
Some examples here.
XOR Gate
++-++-+-*-++-+-*+--+-+--+-+-*+++-*
++- is 1, +- is 0. you can change ++-++- to other things.
Cat program
+*----++-++-++-++*
NOT Gate
+-+-+-*+++-*
About the first character: + is 1, delete the + is 0. Result is in the first byte.
Interpreter
And there is an interpreter.
a = [0,0,0] o = 0 m = 0 def itp(c): global a,o,m '''if any(list(map(lambda x:x>100,a))): print('Because there is a byte\'s value too big so we stopped this program. you can delete this.') __import__('sys').exit() return 255''' r=0 for j,i in enumerate(c): if r==0: if i=='+': a[o] += 1 m = 0 elif i=='-': a[o] -= 1 o += 1 o = o%3 m += 1 if m==3 and (c[j+1]=='-' if j+1<len(c) else 0): a[o]=ord(input()[0]) if m==3: print(chr(a[o])) '''if m==3 and c[j+1]=='-': a[o]=ord(input()[0])''' elif i=='*': m=0 re=__import__('re') goal=re.search(r'[^(\*)](\*)[^(\*)]',c[j+1:]+' ') goal=goal.span()[1] if goal!=None else (print('error:no * found'),__import__('sys').exit()) gotcode='*'+c[j+1:j+goal]+'*' gotcode=delstar(gotcode) while a[o]!=0: itp(gotcode) if i=='*' and c[j+(1 if j<len(c)-1 else 0)]!='*' and c[j-(1 if j>0 else 0)]!='*': r=(r+1)%2 return 0 def delstar(string): re=__import__("re") s=(list(map(lambda x:x[:-1],re.findall(r'\*+',string))))[1:-1] l=(re.split(r'\*+',string))[1:-1] r=[] for i in range(len(s)): print(s,l,r) r.append(l[i]) r.append(s[i]) r.append(l[-1]) return "".join(r) itp('++-++-+-*-++-+-*+--+-+--+-+-*+++-*')#1 XOR 1. Result is in the second byte. #itp('+*+*')#warning: infinite loop. #print(a)#get every bytes' value. #print(delstar('*++**++**++**++***++***+**+*'),'debug')#test function delstar.
I think it is like BrainFuck,but,It isnt an unary...
smile everyday.