sdac2

From Esolang
Jump to navigation Jump to search

sdac2 is a possible stack-based language.

sdac2 has 6 operators: +-/.,* and the two lists. + and-operators work differently in different lists. In the first list, the + and-operators are used to control the addition or subtraction of the current pointer to the value, while in the second list, + Pointer to value added to the list Pointer to value.-Copies the current value to the list without changing the pointer(the pointer in list 1 not be new value).

The / operator is used to switch to another list.

The . operator is used to output the current pointing value.

The * operator is used to loop through the code before the value of 0.

The , operator is used as input in the first list (similar to BF,) and to clear the current value in the second list.

This is written in sdac2 for the Leonardo Pisano number of the procedure:

   +/+/+/+/+/-+-+-+-+-+(and more...)

Interpreter

there is an interpreter:interpreter by python

You can also copy there (code may be bad):


   stack1 = [0];pointer1 = 0;stack2 = [0];pointer2 = 0;now = 1
   def inte(c,r=1):
       global stack1,pointer1,stack2,pointer2,now
       repeat = 0
       if r:
           now = 1
           stack1 = [0]
           pointer1 = 0
           stack2 = [0]
           pointer2 = 0
       if c.count('*') % 2 > 0:
           print('err:there should be a "*"')
           return 1
       for j,i in enumerate(c):
           if now == 1:
               if i == '+':
                   stack1[pointer1] += 1
               elif i == '-':
                   stack1[pointer1] -= 1
               elif i == '.':
                   print(chr(stack1[pointer1])) 
               elif i == ',':
                   stack1[pointer1] = ord(input()[0])
               elif i == '/':
                   now = 2
               elif i == '*':
                   repeat += 1
                   if repeat % 2 == 1:
                       while eval(f'stack{now}[pointer{now}]') != 0:
                           inte(c[j + 1:][:c[j + 1:].index('*')],0)    
           elif now == 2:
               if i == '+' and len(stack1) > 0:
                   stack2[pointer2] += stack1[pointer1]
                   if len(stack1) > 1:
                       stack1.pop(pointer1)
                       pointer1 = 0
                   else:
                       stack1[0] = 0
                       pointer1 = 0
               elif i == '-':
                   pointer1 = 0
                   stack1.insert(0,stack2[pointer2])
                   pointer1 = 1 if len(stack1) > 1 else 0
               elif i == '.':
                   print(chr(stack2[pointer2]))
               elif i == '/':
                   now = 1
               elif i == '*':
                   repeat += 1
                   if repeat % 2 == 1:
                       while eval(f'stack{now}[pointer{now}]') != 0:
                           inte(c[j + 1:][:c[j + 1:].index('*')],0)
               elif i == ',':
                   stack2[pointer2] = 0
       return 0            
   inte('+/+/+/+/+/-+-+-+-+-+-+-+-+.')#fib number
   inte('+/+--+--+--+--+--+--,/+/+-+/,*-/./*')#repeat
   inte('+*.')#error
   inte('run your code there')

The effect of the interpreter may not be as good as you think.

Turing Complete

I don't know that now. :(

Thank those who help others.