Class CompiledDFA<T>

java.lang.Object
org.openzen.zenscript.lexer.CompiledDFA<T>
Type Parameters:
T - final type

public class CompiledDFA<T> extends Object
Represents a compiled DFA. A compiled DFA has a compact representation and is immediately usable for efficient processing.

A compiled DFA can be converted to a compact integer array. This array can then be hardcoded in an application.

  • Field Details

  • Constructor Details

    • CompiledDFA

      public CompiledDFA(Map<Integer,Integer>[] transitions, T[] finals)
      Constructs a compiled DFA from the specified transition graph and finals arrays.

      The transition array specifies all transitions for each state. The finals array specifies the final class index of each state, or NOFINAL if the state is not a final. There can multiple final classes, which can, for example, be used to distinguish token types.

      Parameters:
      transitions - transitions graph
      finals - finals
  • Method Details

    • createLexerDFA

      public static <T extends TokenType & Comparable<T>> CompiledDFA<T> createLexerDFA(T[] tokenTypes, Class<T> tokenClass)
    • eval

      public T eval(String value)
      Determines the token type for the given token. Returns null if the given token is not a valid token.
      Parameters:
      value - token value
      Returns:
      token type
    • matches

      public boolean matches(String value)
      Checks if this value evaluates to a valid token.
      Parameters:
      value - value to check
      Returns:
      true if matching, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object