I've been away for almost a week now debugging, and I got a fairly smooth program now. There is one problem, however, when I used the test sin(((X+1)+cos((2+Y)) (function tokens are treated as if the open was not there). The part labeled "Remove Open" needs a loop to remove an unwanted parenthesis, however I am not sure where to put this or what loop to use.

Code:

```
ClrAllLists
1→dim(⌊IN
1→dim(⌊STACK
1→dim(⌊OUT
Input Str1
0→C
0→D
{16,17,18,19,21→OP
"πXY0123456789+-*/^()sin(cos(tan(sin(cos(tan(sinh(cosh(tanh(sinh(cosh(tanh(√(√(^(^(ln(log(→Str0
seq(inString(Str0,sub(Str1,A,1)),A,1,length(Str1→⌊IN
dim(⌊IN→I
While I-1
If dim(⌊IN
⌊IN(1→N
If not(dim(⌊IN
0→N
dim(⌊STACK→Q
If Q
⌊STACK(Q→P
If not(Q
0→P
Disp "Read
Pause
If N=20
Then
List(cumSum(⌊IN→⌊IN
I-1→I
augment({6,17},⌊IN→IN
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Negative
Pause
End
If max({N≤15
Then
If not(N
Then
If not(dim(⌊IN
0→dim(⌊IN
Else
augment(⌊OUT,{N→OUT
If 1<dim(⌊IN
List(cumSum(⌊IN→⌊IN
I-1→I
If 1=dim(⌊IN
0→dim(⌊IN
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Number
Pause
End
End
If N≥24
Then
augment(⌊STACK,{N→STACK
If ⌊STACK(1)=0
List(cumSum(⌊STACK→⌊STACK
List(cumSum(⌊IN→⌊IN
I-1→I
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Function
Pause
End
If max(N=⌊OP
Then
While max(P=⌊OP
If max(N={16,17 and max(P=⌊OP or max(N={18,19 and max(P={18,19,21
Then
augment(⌊OUT,{P→OUT
Q-1→Q
Q→dim(⌊STACK
⌊STACK(Q→P
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Op:Stack>Out
Pause
End
End
If Q
augment(⌊STACK,{N→STACK
If not(Q
{N→STACK
List(cumSum(⌊IN→⌊IN
I-1→I
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Op:In>Out
Pause
End
If N=22
Then
If Q
augment(⌊STACK,{N→STACK
If not(Q
{N→STACK
List(cumSum(⌊IN→⌊IN
I-1→I
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Open
Pause
End
If N=23
Then
Disp "Close
While max(P=⌊OP
augment(⌊OUT,{P→OUT
Q-1→Q
Q→dim(⌊STACK
If Q
⌊STACK(Q→P
If not(Q
0→P
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Op:Stack>Out
Pause
End
If Q>0
Q-1→Q
Q→dim(⌊STACK
If Q
⌊STACK(Q→P
If not(Q
0→P
If 1<dim(⌊IN
List(cumSum(⌊IN→⌊IN
If 1≥dim(⌊IN
{0→⌊IN
I-1→I
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Remove Open
Pause
If P≥24
Then
augment(⌊OUT,{P→OUT
Q-1→Q
Q→dim(⌊STACK
If Q
⌊STACK(Q→P
If not(Q
0→P
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Pop Function
Pause
End
End
1+C→C
Disp "Loop:",C
Pause
End
While Q
augment(⌊OUT,{P→OUT
Q-1→Q
Q→dim(⌊STACK
If Q
⌊STACK(Q→P
If not(Q
0→P
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Stack>Out
Pause
1+D→D
End
List(cumSum(⌊OUT→⌊OUT
If I
Disp ⌊IN
If not(I
Disp "{}
If dim(⌊OUT
Disp ⌊OUT
If not(dim(⌊OUT
Disp "{}
If Q
Disp ⌊STACK
If not(Q
Disp "{}
Disp "Done
Pause
```

sin(((X+1)+cos((2+Y)) -> X1+2Y+cos(+

**(**sin(