PRSCNT

From Esolang
Jump to navigation Jump to search

PRSCNT is a programming language created by user Someone else.

PRSCNT is based on a different kind of programming paradigm. Instead of describing the particular steps that a program must execute, it is left to the compiler to decide what values variables must be set to and what path the execution of the program follows. The main form of control we have upon execution of the program is instead through the "EQU" and "NEQ" statements, which guarantee that, when a certain line is executed, the values of the variables in the statement are equal or different, respectively. The program thus must in some way previously select the variables and the control flow such that the equality is true/false when the corresponding command is ran. PRSCNT is short for "PReSCieNT", since, in order to select the values correctly the program must already know about the future execution of the program. Sometimes it is logically impossible for some set of equalities/inequalities to hold, in which case a runtime error happens. Meanwhile, when multiple answers are consistent, the program selects one of them randomly.

Description

The language operates on a set of variables. Variables are unbounded non-negative integers. Variable names may contain all alphanumeric characters, and the symbols (?!@$%¨&*()_+=-[]{}:\/~^'"|). The Hash (#) is reserved for comments.

By default, there is only one variable with each name, with a default value of zero.

More variables can be created using the NEW command, and they also have a default value of 0, and shadow old variables with the same name until the newer variables are deleted using the DEL command.

The DEL command can not delete the last remaining variable of a given name, since that would making the result of accessing it undefined. In this case, it is equivalent to a no-op.

Commands

Operating with variables:

SET A, B, C, D... - Changes the value of variables pointed by A, B, C, D...
INC A, B, C, D... - Increments the value of variables pointed by A, B, C, D...
NEW A, B, C, D... - Create new variables to be pointed by A, B, C, D...
DEL A, B, C, D... - Delete variables pointed by A, B, C, D...

Operating with many variables is identical to doing many single-variable operations. For example, "INC A, A, A, A" is the same as writing "INC A" four times.

Execution constraints:

EQU A, B - Guarantees that, at this point, the values of A and B are equal.
NEQ A, B - Guarantees that, at this point, the values of A and B are not equal.

Control Flow:

GSO - Go somewhere. Jumps to the line after a CFS statement.
CFS - Come from somewhere.

Input/Output:

INP A, B, C, D... - Asserts that A, B, C, D... are equal to the next input bytes, respectively
OUT A, B, C, D... - Outputs the ASCII character with value congruent to A mod 256, then B mod 256, then C mod 256...

Comments:

#Empty lines as well as everything after a # sign in a line are ignored.

Examples

Decrementing

Decrement a variable. Will produce an error if Var is zero:

SET Var
INP Var

SET Var--, Var--_copy
EQU Var--, Var--_copy
INC Var--
EQU Var--, Var
SET Var
EQU Var--_copy, Var

OUT Var

Addition

Add two integers:

SET A, B
INP A, B

INC Continueloop

SET Label
EQU Label, Startloop
GSO

CFS
EQU Label, Continueloop
NEQ B, 0

INC A


SET B_dec, B_dec_copy
EQU B_dec, B_dec_copy
INC B_dec
EQU B_dec, B
SET B
EQU B_dec_copy, B

SET Label

CFS
EQU Label, Startloop

SET Label
EQU Label, Continueloop
GSO


CFS
EQU Label, Continueloop
EQU B, 0

OUT A

Computational class

After executing SET on a variable Var1, the variable can have any value. We label that value . Similar with some other variable Var2, we label its value after executing SET on it. Suppose now that NEQ Var1, Var2 appears somewhere. It asserts that . Since both and must be non-negative integers, we can say that either or for some non-negative integers and . We can now substitute either (or ) and keep executing instructions. Variable Var1 is now . We can then execute EQU to Var1 and some other variable whose value is , obtaining . Executing EQU on a variable whose value is and a variable whose value is , we obtain , which gives . Iteratively repeating this process, we can obtain any system of linear equations and inequalities (because each variable is greater or equal to zero).

Solving such system of linear inequalities requires algorithms from linear programming, such as the simplex algorithm of Dantzig, or Gomory's Cutting-plane algorithm. Determining whether a given system of linear inequalities has a solution is uncomputable[citation needed] and is in the same complexity class as the halting problem. Therefore, a PRSCNT program is able to simulate any computation. Note that the language would still be Turing-complete even without the commands NEW and DEL.

If we require the interpreter to throw an error in case when the program imposes unsatisfiable constraints, then the programming language is uncomputable.

Interpreters

Interpreter written by User:Hakerh400