Class Automaton.Transformer<B,R>

java.lang.Object
eu.bandm.tools.lexic.Automaton.Transformer<B,R>
Type Parameters:
B - the behavior type in transformer results
R - the type of transformer results
Enclosing class:
Automaton<L,T>

protected abstract class Automaton.Transformer<B,R> extends Object
Base class for depth-first-search transformers.
  • Field Details

    • newTable

      protected final Map<Automaton.State,B> newTable
      The behavioral table for the result.
  • Constructor Details

    • Transformer

      protected Transformer()
  • Method Details

    • transform

      protected final Automaton.State transform(Automaton.State oldState)
      Transforms a state and its associated behavior.

      This method can be called multiple times, even recursively, with idempotent results. Results are cached such that a safe depth-first search of the automaton can be implemented straightforwardly.

      Parameters:
      oldState - the state to be transformed
      Returns:
      the state that the given state is transformed into
    • makeState

      protected Automaton.State makeState(Automaton.State oldState)
      Returns the new state that the given old state is transformed into.

      This method will be called exactly once for any state to be transformed. The default implementation creates a new state. Subclasses may override this method to reuse pre-existing states instead.

      Parameters:
      oldState - the state to be transformed
      Returns:
      the state that the given state is transformed into
    • makeBehavior

      protected abstract B makeBehavior(Automaton.State oldState, Behavior<L,T> oldBehavior)
      Returns the behavior that the given behavior is transformed into.

      This method will be called exactly once for any state to be transformed. At that time, there will be no associated behavior in newTable. When this method returns, the result is added.

      Subclasses must implement this method. If the behavior contains references to old states, then these must be recursively transformed to new states according to transform(State). Usually an expression of the form b.map(this::transform) will do.

      Parameters:
      oldState - the state to be transformed
      oldBehavior - the behavior for the state to be transformed
      Returns:
      the behavior that the given behavior is transformed into
    • transform

      public R transform(BiFunction<Automaton.State,Map<Automaton.State,B>,? extends R> cons)
      Transforms all reachable states of the automaton.

      A state t is directly reachable from state s if a reference to t occurs in the behavior associated with s. Indirect reachability is the reflexive-transitive closure of direct reachibility. A state is reachable if it is indirectly reachable from the initial state. Unreachable states are ignored by the transformation.

      Parameters:
      cons - the operation to construct the final result
      Returns:
      the result of applying cons to the new initial state and behavioral table