Executing if statements

I created my own programming language that compiles before the Turing Machine instructions, and I was wondering how to implement it if(a>b) do _ end. Here's the language definition (also available here )

Variables are dynamically distributed over any width, so they can have arbitrarily large integers

Each line can perform one of three functions, it can call a function (which changes its argument), run a while loop (which is really more from the for loop), or assign a variable.

Available functions: incr(Increment by one, may overflow), decr(Decrease by one, overflow), pop(Delete the last digit from the variable), first(Changes the most significant value of 0 in the variable to 1) and frost(changes the most significant 1 to zero).

The while loop has the following syntax:

while a <func> {
    _
}

Basically, every time he loops, he is <func>up ato the error state. The error conditions are as follows: incrit firsthas all 1, decrand frosthas all 0, popdeletes the last digit. After a while loop with incror, frostall bits of the loop variable will be 0, on the contrary - firstand decr. Although the loops should end with a function call, and they delete all the variables contained within each run.

. a=b b , a, b , a, undefined, a - . a=b,5 b a ( ) , undefined, a . a=a,0 a. a=5,3 5 % 2**3 to a 3 .

if(a != 0) do _ end

while a decr {
    _
    t=0,1
    while a incr {
        incr(t)
    }
    incr(t)
}

, if, if(a==b), if(a!=b) if(a>b)

- Turing Complete, , , Turing?. , 1-5, 6.

+4
1

(, , incr/decr, )

if(a!=0) . , while(a) do _ end, , . , t , -, , , (true/false ).

, // comment/c-style, .

, - ...

if (a > 0) do _ end

// if (a > 0) do _ end
_a = a
while _a decr {
    // overflow iif _a= 0
    _ // do something
    _a = 0
    frost( _a ) // only function calls at end of loops
}

if (a == 0) do _ end

// if (a == 0) do _ end
_a = a
result = 1,1
while _a decr {
    // overflow iif _a= 0
    _a = 0
    frost( result ) // only function calls at end of loops
}
while result decr {
    // overflow iif result = 0
    _ // do something
    frost( result ) // exit loop
}

, , - , ( ), -, 1 . Trick while, , decr 0 . frost , 0 , 1 0, , result.

, , , , .

: a > b a == b; / , result.

if (a == b) do _ end

// if( a == b ) do _ end
a_cond = a
b_cond = b
// step 1: a_cond = a - b
while b_cond decr {
    decr(a_cond)
}
// step 2: if (a_cond == 0)
result = 1,1
while a_cond decr {
    // overflow iif a_cond = 0
    a_cond = 0
    frost( result ) // only function calls at end of loops
}
while result decr {
    // overflow iif result = 0
    _ // do something
    frost( result ) // exit loop
}

if (a > b) do _ end

WIP. (a == b)

0

All Articles