Execute Brain****/TI-83 BASIC: Difference between revisions

I'm usd to markdown formatting and forgot to hit the preview button
m (Comment about speed)
(I'm usd to markdown formatting and forgot to hit the preview button)
 
(16 intermediate revisions by 5 users not shown)
Line 1:
[[Category:TI-83 BASIC]]{{implementation|Brainf***}}{{collection|RCBF}}
This implementation (in [[TI-83 BASIC]]) has quite a few limitations. Among them:
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. The speed of this program isn't pretty. The code <tt>,[.-]</tt> works as a pretty good seconds countdown. The calculator probably wasn't designed with these kinds of string operations in mind.
 
<br clear=all>
* TI-BASIC doesn't have any concept of ASCII, so the <tt>.</tt> command, which is translated to <tt>Disp </tt>, outputs everything on a new line as a number. Input is taken whenever a comma is encountered as opposed to being presupplied, and again takes numbers as input. [Attempting to input a string (enclosed in "quotes") will, because of a weird glitch in the interpreter, work without throwing an error: it stores the string to a custom list (yes, a list) named 'V', not the variable V (which remains unaffected). Attempting to access this list throws an ERR:DATA TYPE.]
"+-.,[]<>"→Str2
* In order to simplify the main loop, all commands are stored to list L1 at the beginning. Lists (arrays) in TI-BASIC can't be more than 999 elements, so attempting to run a program exceeding that size will throw an error (probably INVALID DIM). This can be fixed at the cost of speed and size.
" "→Str3
* Speaking of which: the interpreter is... on the slow side, to put it nicely.
{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}→L<sub>1</sub>
 
" "→Str5
This was made to be compatible with [http://sc.cemetech.net SourceCoder], so the tilde (~) translates to the negative sign (the <tt>(-)</tt> key) and -> is the arrow on the STO> key.
Input Str1
 
0→B
Input "",Str1 //program input
1→P
Forseq(AinString("<>-+.,[]",sub(Ans,S,1)),S,1,length(Str1))->L2
cumSum((Ans=7)-(Ans=8->L3
If inString(Str2,sub(Str1,A,1))>0:Then
seq(Ans(X),X,dim(Ans),1,~1->L4
Str3+sub(Str1,A,1)→Str3
1->P:DelVar L11->dim(L1 //this is the same as DelVar L1:1->dim(L1 as DelVar doesn't require a colon or newline after its argument
If sub(Str1,A,1)="["
For(S,1,dim(L2
B+1→B
L2(S->T
If sub(Str1,A,1)="]"
P-(T=1)+(T=2->P //< and >, respectively
B-1→B
dim(L1
Ans+(P-Ans)(P>Ans->dim(L1
L1(P)-(T=3)+(T=4->L1(P //- and +
If T=5 //.
Disp L1(P
If T=6:Then //,
Input Str1V
V->L1(P
End
If T=7 and not(L1(P //[
S+2+sum(not(cumSum(L3(S)-1=seq(L3(X),X,S+1,dim(L3->S
If T=8 and L1(P:Then //]
1+dim(L3)-S
(Ans+S)-(Ans+sum(not(cumSum(L4(Ans)=seq(L4(X),X,Ans+1,dim(L4->S
End
If B&ne;0:Then
Disp "UNEVEN BRACKETS"
Stop
End
For(A,2,length(Str3))
sub(Str,A,1)→Str4
If Str4="+"
L<sub>1</sub>(P)+1→L<sub>1</sub>(P)
If Str4="-"
L<sub>1</sub>(P)-1→L<sub>1</sub>(P)
If Str4="."
Disp L<sub>1</sub>(P)
If Str4=",":Then
Input B
int(B)→L<sub>1</sub>(P)
End
If Str4="[" and L<sub>1</sub>(P)=0:Then
1→B
A+1→A
While A≤length(Str3) and B&ne;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 L<sub>1</sub>(P)=0:Then
1→B
A-1→A
While A≥0 and B&ne;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
Anonymous user