fr.umlv.tatoo.runtime.parser
Class StateMetadata<T,N,V>

java.lang.Object
  extended by fr.umlv.tatoo.runtime.parser.StateMetadata<T,N,V>
Type Parameters:
T - type of terminals.
N - type of non-terminals.
V - type of versions.

public abstract class StateMetadata<T,N,V>
extends Object

Data associated to a state of the parsing table. This class contains basically to kind of state :

  1. a set of compatible versions of the state, see Parser.reset(Object) or Parser.setVersion(Object).
  2. the terminal shifted by or the non-terminal reduced by the state, this information is used by the default error recovery mechanism if a state must be dropped to recover on error to signal to the ErrorRecoveryListener which terminal or non terminal value that must be pop from the stack.

    Author:
    Remi Forax

    Constructor Summary
    StateMetadata()
               
     
    Method Summary
    static
    <T,N,V> StateMetadata<T,N,V>
    createAllVersionWithNonTerminal(N nonTerminal)
              Creates a state data compatible with all versions that reduce a non terminal.
    static
    <T,N,V> StateMetadata<T,N,V>
    createAllVersionWithTerminal(T terminal)
              Creates a state data compatible with all versions that shift a terminal.
    static
    <T,N,V> StateMetadata<T,N,V>
    createWithNonTerminal(Set<?> compatible, N nonTerminal)
              Creates a state data compatible with a set of versions that reduce a non terminal.
    static
    <T,N,V> StateMetadata<T,N,V>
    createWithTerminal(Set<?> compatible, T terminal)
              Creates a state data compatible with a set of versions that shift a terminal.
     boolean isCompatible(V version)
              Returns true if the state is compatible with the version taken as argument.
    abstract  void popVariableOnError(ErrorRecoveryListener<? super T,? super N> listener)
              Called by the default error recovery mechanism to adjust the stack of value used by the evaluator.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    StateMetadata

    public StateMetadata()
    Method Detail

    isCompatible

    public boolean isCompatible(V version)
    Returns true if the state is compatible with the version taken as argument. This default implementation always return true.

    Parameters:
    version - the version
    Returns:
    true if the state is compatible with the version.

    popVariableOnError

    public abstract void popVariableOnError(ErrorRecoveryListener<? super T,? super N> listener)
    Called by the default error recovery mechanism to adjust the stack of value used by the evaluator. This implementation calls ErrorRecoveryListener.popNonTerminalOnError(Object) if the current state is a reduce with a non terminal or ErrorRecoveryListener.popTerminalOnError(Object) id the current state is a shift with a terminal.

    Parameters:
    listener - the error recovery listener

    createAllVersionWithTerminal

    public static <T,N,V> StateMetadata<T,N,V> createAllVersionWithTerminal(T terminal)
    Creates a state data compatible with all versions that shift a terminal.

    Type Parameters:
    T - type of terminal
    N - type of non terminal
    V - type of version
    Parameters:
    terminal - the shifted terminal
    Returns:
    a new state data.

    createAllVersionWithNonTerminal

    public static <T,N,V> StateMetadata<T,N,V> createAllVersionWithNonTerminal(N nonTerminal)
    Creates a state data compatible with all versions that reduce a non terminal.

    Type Parameters:
    T - type of terminal
    N - type of non terminal
    V - type of version
    Parameters:
    nonTerminal - the reduced non terminal
    Returns:
    a new state data.

    createWithTerminal

    public static <T,N,V> StateMetadata<T,N,V> createWithTerminal(Set<?> compatible,
                                                                  T terminal)
    Creates a state data compatible with a set of versions that shift a terminal.

    Type Parameters:
    T - type of terminal
    N - type of non terminal
    V - type of version
    Parameters:
    compatible - a set of compatible versions
    terminal - the shifted terminal
    Returns:
    a new state data.

    createWithNonTerminal

    public static <T,N,V> StateMetadata<T,N,V> createWithNonTerminal(Set<?> compatible,
                                                                     N nonTerminal)
    Creates a state data compatible with a set of versions that reduce a non terminal.

    Type Parameters:
    T - type of terminal
    N - type of non terminal
    V - type of version
    Parameters:
    compatible - a set of compatible versions
    nonTerminal - the reduced non terminal
    Returns:
    a new state data.