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

I'm usd to markdown formatting and forgot to hit the preview button
(Some extra explanation)
(I'm usd to markdown formatting and forgot to hit the preview button)
 
(8 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 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 <tt>,[.-]</tt> works as a pretty good seconds countdown. The calculator probably wasn't designed with these kinds of string operations in mind.
 
* 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.]
String variable definitions:
* 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.
*Str1: raw input
* Speaking of which: the interpreter is... on the slow side, to put it nicely.
*Str2: valid code characters
 
*Str3: cleaned up code (removing illegal characters)
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.
*Str4: each individual instruction (basically a loop variable for each character in Str3).
 
"+-.,[]<>"→Str2
Input "",Str1 //program input
" "→Str3
seq(inString("<>-+.,[]",sub(Ans,S,1)),S,1,length(Str1->L2
{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>
cumSum((Ans=7)-(Ans=8->L3
" "→Str5
seq(Ans(X),X,dim(Ans),1,~1->L4
Input Str1
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
0→B
For(AS,1,lengthdim(Str1))L2
1→P
L2(S->T
For(A,1,length(Str1))
P-(T=1)+(T=2->P //< and >, respectively
If inString(Str2,sub(Str1,A,1))>0:Then
dim(L1
Str3+sub(Str1,A,1)→Str3
Ans+(P-Ans)(P>Ans->dim(L1
If sub(Str1,A,1)="["
L1(P)-(T=3)+(T=4->L1(P //- and +
B+1→B
If T=5 //.
If sub(Str1,A,1)="]"
Disp L1(P
B-1→B
If T=6:Then //,
End
Input Str1V
End
V->L1(P
If B&ne;0:Then
Disp "UNEVEN BRACKETS"
Stop
End
For(A,2,length(Str3))
sub(Str3,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(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 L<sub>1</sub>(P)&ne;0:Then
1→B
A-1→A
While A≥0 and B&ne;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 T=7 and not(L1(P //[
If Str4=">":Then
S+2+sum(not(cumSum(L3(S)-1=seq(L3(X),X,S+1,dim(L3->S
P+1→P
If T=8 and L1(P:Then //]
If P>dim(L<sub>1</sub>)
1+dim(L3)-S
0→L<sub>1</sub>(P)
(Ans+S)-(Ans+sum(not(cumSum(L4(Ans)=seq(L4(X),X,Ans+1,dim(L4->S
End
End
Anonymous user