Class TokenRuleSet<T>

java.lang.Object
eu.bandm.tools.lexic.TokenRuleSet<T>
Type Parameters:
T - the type of token types

public class TokenRuleSet<T> extends Object
A set of token rules together with a precendence relation between token types.

An object of this class completely defines the lexical structure of a formal language.

FIXME: documentation of union and precedence

  • Constructor Details

    • TokenRuleSet

      @SafeVarargs public TokenRuleSet(TokenRule<T>... rules)
      Creates a new instance with the given rules and the empty precedence relation.
      Parameters:
      rules - the token rules
    • TokenRuleSet

      @SafeVarargs public TokenRuleSet(BiPredicate<? super T,? super T> precedenceOracle, TokenRule<T>... rules)
      Creates a new instance with the given rules and precedence relation.
      Parameters:
      precedenceOracle - a predicate that encodes the precedence relation
      rules - the token rules
    • TokenRuleSet

      public TokenRuleSet(Collection<? extends TokenRule<T>> rules)
      Creates a new instance with the given rules and the empty precedence relation.
      Parameters:
      rules - the token rules
    • TokenRuleSet

      public TokenRuleSet(BiPredicate<? super T,? super T> precedenceOracle, Collection<? extends TokenRule<T>> rules)
      Creates a new instance with the given rules and precedence relation.
      Parameters:
      precedenceOracle - a predicate that encodes the precedence relation
      rules - the token rules
  • Method Details

    • getRules

      public Set<TokenRule<T>> getRules()
      Returns the set of token rules.
      Returns:
      an unmodifiable set containing the token rules
    • filterByPrecedence

      public List<T> filterByPrecedence(Collection<T> types)
      Returns the preferred token types from a given collection according to the precedence relation.
      Parameters:
      types - a collection of token types
      Returns:
      a list containing only the preferred among the given token types