state = start transition = transition-for (state, input.current-char) if (transition.is-good) { state = transition.state # move if (state.accepts) { # memo memo.type = state.type memo.position = input.position } advance (input) # advance } else { push (output-queue, token (memo.type)) # token input.position = memo.position # rewind state = start # restart } #### state = start last-start = input.position transition = transition-for (state, input.current-char) if (transition) { state = transition.state # move if (state.accepts) { # memo memo.type = state.type memo.position = input.position } advance (input) # advance } else { push (output-queue, token { # token type = memo.type value = input.character-range ( last-start memo.position ) }) input.position = memo.position + 1 # rewind state = start # restart last-start = input.position } #### state = start memo.last-start = input.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 memo.last-accept = input.position } advance (input) # advance } else { push (output-queue, token { # token type = memo.type value = input.character-range ( last-start memo.position ) }) input.position = memo.position + 1 # rewind state = start # restart last-start = input.position } } #### 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 } } #### state = start input->remember-start-position while (input.has-more) { if (state.has-transition-for (input.current)) { state = state.transition-for (input.current-char) # move if (state.accepts) { # memo last-accept = state input->remember-accept-position } input->advance # advance } else { push (output-queue, token { # token type = last-accept.type value = input.accepted-string }) input->rewind # rewind state = start # restart input->remember-start-position } } #### state = start input->remember-starting-position while (input->has-more) { if (t = state->transition-for (input->current-char)) { state = t->new-state # move if (state->accepts) { # memo last-accept-state = state input->remember-accept-position } input->advance # advance } else { push (output-queue, token { # token type = last-accept-state->type input->last-accepted-string }) input->rewind # rewind state = start # restart input->remember-starting-position } } #### state = start input->remember-starting-position while (input->has-more) { state = state->transition-for (input->current-char) || error-state # move if (state->is-error) { push (output-queue, token { # token type = last-accept-state->type value = input->last-accepted-string }) input->rewind # rewind state = start # restart input->remember-starting-position } else { if (state->accepts) { # memo last-accept-state = state input->remember-accept-position } input->advance # advance } } #### regular-state::process (input) { input->remember-accept-position if (self->accepts) # memo-2 input->advance # advance } error-state::process (input) { push (output-queue, token { # token type = last-accept.type value = input->last-accepted-string }) input->rewind # rewind } error-state::transition-for (char) { return (start) # restart-1 } start-state::process (input) { input->remember-starting-position # restart-2 } state = start-state while (input->has-more) { last-accept = state if (state->accepts) # memo-1 state->process (input) state = state->transition-for (input->current-char) || error-state # move } #### regular-state::process (config) { if (self->accepts) { # memo config->remember-accept-position config->remember-accept-type (self->type) } config->advance-input # advance } error-state::process (config) { push (output-queue, token { # token type = config->accepted-type value = config->accepted-string }) config->rewind-input # rewind } error-state::transition-for (char) { return (start) # restart-1 } start-state::process (config) { config->remember-starting-position # restart-2 } state = start while (config->has-more-input) { state->process (config) state = state->transition-for (config->current-input-char) || error-state # move }