proc expression {curr: Int, input: [Int], ret: Int} ~ (operator expression expression) if input.(curr) = '(' curr += 01 var op := input.(curr) curr += 01 var a := 0 var b := 0 do expression {curr, input, a} do expression {curr, input, b} if op = 043 ret += a + b else if op = 045 ret += a - b else if op = 042 ret += a * b else if op = 047 ret += a / b else error("unrecognized op") fi fi fi fi undo expression {curr, input, b} undo expression {curr, input, a} drop b := 0 drop a := 0 curr -= 01 drop op := input.(curr) curr += 03 ~ number else if input.(curr) >= 048 && input.(curr) < 058 ret += input.(curr) - 048 ~ error else error("neither a group nor a number") fi fi input.(curr) = ')' curr += 01 return proc main var curr := 0 var input := "(/33)" var result := 0 do expression {curr, input, result} do show {result} drop result := 0 drop input := 0 drop curr := 05 return