Advertisement
imk0tter

calculate input in debug

May 7th, 2021
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. alias calctok {
  2. hinc -m CALCTOKEN COUNT
  3. var %htable CALCTOKEN $+ $hget(CALCTOKEN,COUNT)
  4. hadd -m %htable COUNT 0
  5.  
  6. var %tokens $1-
  7.  
  8. var %numberOfTokens $pos(%tokens,$chr(40),0)
  9. var %currentCalculation
  10.  
  11. while %numberOfTokens {
  12. var %numberOfOpeners $pos(%tokens,$chr(40),0)
  13.  
  14. var %currentOpenerOffset $pos(%tokens, $chr(40), %numberOfOpeners)
  15. var %currentCloserOffset $calc(%currentOpenerOffset + $pos($mid(%tokens,%currentOpenerOffset $+ -),$chr(41),1))
  16. var %length $calc(%currentCloserOffset - %currentOpenerOffset)
  17.  
  18. var %currentCalculation $mid($mid(%tokens,$calc(%currentOpenerOffset),%length),2,-1)
  19.  
  20. var %tokens $mid(%tokens,1,$calc(%currentOpenerOffset - 1)) @ $mid(%tokens, %currentCloserOffset $+ -)
  21.  
  22. if (@ !isin %currentCalculation) spush %htable %currentCalculation
  23. else {
  24. var %z $pos(%currentCalculation,@,0)
  25.  
  26. while %z {
  27. var %currTok $spop(%htable)
  28. var %currentCalculation $replacetok(%currentCalculation,@,-1,$calc(%currTok))
  29. if (@ !isin %currentCalculation) spush %htable %currentCalculation
  30. dec %z
  31. }
  32. }
  33. dec %numberOfTokens
  34. }
  35. hfree %htable
  36. return %currentCalculation
  37. }
  38. alias replacetok {
  39. var %pos $pos($1,$2,$iif($3 > 0,$3,$calc($pos($1,$2,0) + $3 + 1)))
  40. return $+($left($1,$calc(%pos - 1)),$$4,$right($1,- $+ $calc(%pos + $len($2) - 1)))
  41. }
  42.  
  43. alias -l spush {
  44. var %htable $1
  45. hinc -m %htable COUNT
  46. hadd -m %htable $hget(%htable,COUNT) $2-
  47. }
  48.  
  49. alias -l spop {
  50. var %htable $1, %count $hget(%htable,COUNT)
  51. hdec -m %htable COUNT
  52. return $hget(%htable,%count)
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement