Now handle all four operators: +, -, *, /. Try "3+4*5" (left-to-right, no precedence yet -- so 35, not 23). Try "5-3", "4*7", "8/2".
For division, use @divTrunc(a, b) -- Zig wants you to be explicit about how to round.
In the interpreter loop, read the operator first, then dispatch.
while (input_pos < input.len) {
const op: u8 = input[input_pos];
input_pos += 1;
const next_digit: i64 = @as(i64, input[input_pos]) - '0';
input_pos += 1;
// YOU: dispatch on op for '+', '-', '*', '/'.
// for anything else, printString("error").
}
if (op == '+') {
result = result + next_digit;
} else if (op == '-') {
result = result - next_digit;
} else if (op == '*') {
result = result * next_digit;
} else if (op == '/') {
result = @divTrunc(result, next_digit);
} else {
printString("error: unknown operator\n");
return;
}
9-3-1 is 5 (left-to-right: (9-3)-1). 8/2/2 is 2. Precedence -- where * and / outrank + and - -- comes much later.