21
2
Here is a very simple language definition:
A Variable is any string that does not contain ^, <, >, !, or ?
The empty string is a valid variable identifier
The value of every variable starts at 0.
A Statement is one of (var is a Variable, P is a Program):
var^ -> changes var to be equal to 1 more than itself
var<P> -> while var > 0, changes var to be equal to 1 less than itself, then runs P
var! -> output value of var
var? -> ask for non-negative integer as input, increase var by that value
A Program is a concatenation of Statements, running a Program means running each Statement in order
Example programs (note that the empty string is a variable, but I will use it sparingly for the sake of clarity, and some variables are zeroed out in the program when they are usually 0 by default):
<>: sets the value of the empty string variable to 0
b<>b?b<a^>: asks for b, then adds the value stored in b to a, zeroing b in the process
b<>b?a<>b<a^>: asks for b, then sets a to the value of b, zeroing b in the process
a<>c<>b<a^c^>c<b^> : copies the value in b into a without zeroing it
b<>c<>a<c^c^c<b^>>b! : outputs a multiplied by 2
b^b<a<>a?a!b^> : outputs what you input, forever
Your goal is to write the smallest interpreter for this language.
The value of a variable can be arbitrarily large and should only be limited by the total memory your language has access to, in theory, but you are only required to handle values up to 2^256.
Your program should be able to handle arbitrarily long programs, in theory, but you will only be required to work on programs under 2^32 characters long. You are required to handle nested loops of depth up to 2^32 as well.
You can assume that the program is a valid program, and that you will only ever get non-negative integers when you ask for input. You can also assume that only ASCII printable characters are included in the input string.
The speed of the program you interpret doesn't matter, it will already be painfully slow for things as simple as 5-digit multiplication, without optimization.
If you want to use a language which cannot reasonably accept input or produce output in the way described by the language, use any interpretation you want to make it possible. This applies to any reason your language can't implement some required behavior. I want all languages to be able to compete.
Shortest program wins. Standard loopholes apply.
As a side challenge I want to see how short a program I can write that outputs the number 2016, but first I need to wait for an interpreter to be written so that I can test my code. – Neil – 2016-02-10T20:28:22.840
1
I have an interpreter in Python 2.7 here.
– Fricative Melon – 2016-02-10T20:40:55.5402
What is this language called? It deserves a place at http://esolangs.org
– wizzwizz4 – 2016-02-11T19:45:17.670@Neil I managed to do it in 72 characters – Fricative Melon – 2016-02-11T19:56:00.053
@FricativeMelon 72? I can do it in 43! – Neil – 2016-02-11T20:00:10.443
@Neil I've gotten mine down to 39 – Fricative Melon – 2016-02-11T20:53:19.117
@FricativeMelon Looks like you've got me beat; 726262 took me 45, while 822(824-1) took me 43. – Neil – 2016-02-12T08:46:54.293
@Neil 60415263063373835637355132068513997507264512000000000 is a heck of a lot of characters – undergroundmonorail – 2016-02-12T09:24:55.693
@FricativeMelon 72829 is also 43, but I've now found 73834, which is only 42... – Neil – 2016-02-12T21:16:29.603
@FricativeMelon At last, I've managed 39:
^^^^<a^a^>a<^^^^><a^b^>a<c<b^^>b<c^^>>!
– Neil – 2016-02-12T21:31:23.540I don't think any of the answers actually support 256-bit variables. – 12Me21 – 2018-02-15T18:36:01.927