state = start input->remember-start-position while (input.has-more) { transition = transition-for (state, input.current-char) if (transition.is-good) { state = transition.state # move if (state.accepts) { # memo memo.type = state.type input->remember-accept-position } input->advance # advance } else { push output-queue, token ( # token memo.type input.accepted-string ) input->rewind # rewind state = start # restart } }