Execute Brain****/TI-83 BASIC

From Rosetta Code
Revision as of 05:16, 3 April 2008 by rosettacode>Mwn3d (More input clarification)
Execute Brain****/TI-83 BASIC is an implementation of Brainf***. Other implementations of Brainf***.
Execute Brain****/TI-83 BASIC is part of RCBF. You may find other members of RCBF at Category:RCBF.

This implementation 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. This program initializes the memory space to 35 elements (all 0's). To expand the space, an element must be added one space after the end and no farther. 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 a word is typed in quotes as input, an error is thrown since it is expecting a number and the program exits.

"+-.,[]<>"→Str2
" "→Str3
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}→L1
" "→Str5
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
End
End
If B≠0:Then
Disp "UNEVEN BRACKETS"
Stop
End
For(A,2,length(Str3))
sub(Str,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(Str1,A,1)="["
B+1→B
If sub(Str1,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(Str1,A,1)="["
B-1→B
If sub(Str1,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=">"
P+1→P
End