Calculator based on finite state machine