Hi all,
I am trying to make a simple reverse polish notation calculator and I am having a problem with my stack going out of the array dimensions. I have tried many different attempts and tricks for it to work, but no luck yet. I read on the TI-Basic Developer wiki site that the return command could be used to break out of a loop, just as the break statement in C++ does, but the only thing it does is as expected, end the program. The error occurs when S is decremented and the program checks for an element that is out of range. Any ideas how I can rearrange my loop or break out of it to prevent the program from checking for list element 0?
Thanks in advance.
Code:
[/code]
I am trying to make a simple reverse polish notation calculator and I am having a problem with my stack going out of the array dimensions. I have tried many different attempts and tricks for it to work, but no luck yet. I read on the TI-Basic Developer wiki site that the return command could be used to break out of a loop, just as the break statement in C++ does, but the only thing it does is as expected, end the program. The error occurs when S is decremented and the program checks for an element that is out of range. Any ideas how I can rearrange my loop or break out of it to prevent the program from checking for list element 0?
Thanks in advance.
Code:
:Clrhome
:SetUpEditor ʟSTACK
:1→S
:"?→Str2
:Input "STR1: ",Str1
:Str1+"?→Str1
:For(θ,1,length(Str1
:If instring("-.0123456789",sub(Str1,θ,1
:Then
:While instring("-.0123456789",sub(Str1,θ,1
:Str2+sub(Str1,θ,1→Str2
:θ+1→θ
:End
:Str2+" "→Str2
:End
:If sub(Str1,θ,1)="^"
:Then
:1→ʟSTACK(S
:S+1→S
:End
:If sub(Str1,θ,1)="*"
:Then
:If dim(ʟSTACK)=0
:Then
:2→ʟSTACK(S
:S+1→S
:Else
:S-1→S
:While S>0 and ʟSTACK(S)≤2
:Str2+sub("^*",ʟSTACK(S),1→Str2
:Str2+" "→Str2
:S-1→S
:End
:S→dim(ʟSTACK
:S+1→S
:End
:End
:End