Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alias calctok {
- hinc -m CALCTOKEN COUNT
- var %htable CALCTOKEN $+ $hget(CALCTOKEN,COUNT)
- hadd -m %htable COUNT 0
- var %tokens $1-
- var %numberOfTokens $pos(%tokens,$chr(40),0)
- var %currentCalculation
- while %numberOfTokens {
- var %numberOfOpeners $pos(%tokens,$chr(40),0)
- var %currentOpenerOffset $pos(%tokens, $chr(40), %numberOfOpeners)
- var %currentCloserOffset $calc(%currentOpenerOffset + $pos($mid(%tokens,%currentOpenerOffset $+ -),$chr(41),1))
- var %length $calc(%currentCloserOffset - %currentOpenerOffset)
- var %currentCalculation $mid($mid(%tokens,$calc(%currentOpenerOffset),%length),2,-1)
- var %tokens $mid(%tokens,1,$calc(%currentOpenerOffset - 1)) $mid(%tokens, %currentCloserOffset $+ -)
- if ( !isin %currentCalculation) spush %htable %currentCalculation
- else {
- var %z $pos(%currentCalculation,,0)
- while %z {
- var %currTok $spop(%htable)
- var %currentCalculation $replacetok(%currentCalculation,,-1,$calc(%currTok))
- if ( !isin %currentCalculation) spush %htable %currentCalculation
- dec %z
- }
- }
- dec %numberOfTokens
- }
- hfree %htable
- return $calc(%currentCalculation)
- }
- alias replacetok {
- var %pos $pos($1,$2,$iif($3 > 0,$3,$calc($pos($1,$2,0) + $3 + 1)))
- return $+($left($1,$calc(%pos - 1)),$$4,$right($1,- $+ $calc(%pos + $len($2) - 1)))
- }
- alias -l spush {
- var %htable $1
- hinc -m %htable COUNT
- hadd -m %htable $hget(%htable,COUNT) $2-
- }
- alias -l spop {
- var %htable $1, %count $hget(%htable,COUNT)
- hdec -m %htable COUNT
- return $hget(%htable,%count)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement