eq$ = "5-3+2+7-1"
 
print eq$," = ",evaluate(eq$)
 
wait key
 
 
 
 
function evaluate(eq$)
   last = 0
   answer = 0
 
   flag = 0
   for i = 1 to len(eq$)
      c$ = mid$(eq$,i)
      if c$ = "+" then inc flag
      if c$ = "-" then inc flag
      `if c$ = "*" then inc flag
      if flag = 1
         answer = val(right$(left$(eq$,i-1),(i-1)-last))
         last = i
         inc flag
      endif
 
      if flag > 2
         sign$ = mid$(eq$,last)
         p$ = right$(left$(eq$,i-1),(i-1)-last)
         last = i
         answer = calc(answer,val(p$),sign$)
         flag = 2
      endif
 
      if i = len(eq$)
         sign$ = mid$(eq$,last)
         p$ = right$(left$(eq$,i),i-last)
         answer = calc(answer,val(p$),sign$)
      endif
   next i
 
endfunction answer
 
 
 
 
function calc(a as integer, b as integer, sign as string)
   select sign
      case "+" : c = a+b : endcase
      case "-" : c = a-b : endcase
      case "*" : c = a*b : endcase
      case "/" : c = a/b : endcase
   endselect
endfunction c