Execute Brain****/TI-83 BASIC: Difference between revisions
(Oops! I meant to change it to Str3!) |
(You can add 0's one at a time to extend the array as needed) |
||
Line 66: | Line 66: | ||
If Str4=">":Then |
If Str4=">":Then |
||
P+1→P |
P+1→P |
||
If P> |
If P>dim(L<sub>1</sub>) |
||
0→L<sub>1</sub>(P) |
|||
Disp "PTR OUT OF RANGE" |
|||
Stop |
|||
End |
|||
End |
End |
||
End |
End |
Revision as of 19:49, 30 November 2009
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 ,[.-] works as a pretty good seconds countdown. The calculator probably wasn't designed with these kinds of string operations in mind.
"+-.,[]<>"→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(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(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=">":Then P+1→P If P>dim(L1) 0→L1(P) End End