Execute Brain****/TI-83 BASIC
This implementation (in TI-83 BASIC) is extremely limited by the TI-83 calculator. The closest thing the calculator has to an array for memory space is a list. Lists in the calculator can't be given a size, they have to be filled in element by element. To expand the space, an element must be added one space after the end and no farther. This program increases the list length as the BF program needs it (dynamically), so it will never run out of space so long as the calculator has the memory to support it. The maximum memory space size is dependent on the amount of memory already taken up by variables and other programs, but is theoretically unlimited. Also, the calculator doesn't use ASCII, so its input and output is a bit different. It takes in a single number (any number of digits, truncates decimal places) for input, and outputs a single number (any number of digits) on each line. If letters are used on input, their variable value is used. For undefined variables, 0 is used. For words typed in without quotes, all of the variables are multiplied and that result is used (if any variable is not defined, 0 is used for that variable). If a word is typed in quotes as input, an error is thrown since it is expecting a number and the program exits. The speed of this program isn't pretty. The code ,[.-] works as a pretty good seconds countdown. The calculator probably wasn't designed with these kinds of string operations in mind.
String variable definitions:
- Str1: raw input
- Str2: valid code characters
- Str3: cleaned up code (removing illegal characters)
- Str4: each individual instruction (basically a loop variable for each character in Str3).
"+-.,[]<>"→Str2 " "→Str3 {0}→L1 Input Str1 0→B 1→P For(A,1,length(Str1)) If inString(Str2,sub(Str1,A,1))>0:Then Str3+sub(Str1,A,1)→Str3 If sub(Str1,A,1)="[" B+1→B If sub(Str1,A,1)="]" B-1→B If B<0:Then Disp "UNEVEN BRACKETS" Stop End End End If B≠0:Then Disp "UNEVEN BRACKETS" Stop End For(A,2,length(Str3)) sub(Str3,A,1)→Str4 If Str4="+" L1(P)+1→L1(P) If Str4="-" L1(P)-1→L1(P) If Str4="." Disp L1(P) If Str4=",":Then Input B int(B)→L1(P) End If Str4="[" and L1(P)=0:Then 1→B A+1→A While A<length(Str3) and B≠0 If sub(Str3,A,1)="[" B+1→B If sub(Str3,A,1)="]" B-1→B A+1→A End A-1→A End If Str4="]" and L1(P)≠0:Then 1→B A-1→A While A>0 and B≠0 If sub(Str3,A,1)="[" B-1→B If sub(Str3,A,1)="]" B+1→B A-1→A End End If Str4="<":Then P-1→P If P≤0:Then Disp "PTR OUT OF RANGE" Stop End End If Str4=">":Then P+1→P If P>dim(L1) 0→L1(P) End End