Class Symbol

java.lang.Object
org.nineml.coffeegrinder.util.Decoratable
org.nineml.coffeegrinder.parser.Symbol
Direct Known Subclasses:
NonterminalSymbol, TerminalSymbol

public abstract class Symbol extends Decoratable
A grammar symbol.

Symbols match either tokens in the input (for TerminalSymbol symbols) or other symbols (for NonterminalSymbol symbols). For convenience, this interface defines both match methods for all Symbols.

  • Constructor Details

    • Symbol

      public Symbol()
      Create a symbol with no attributes.
    • Symbol

      public Symbol(Collection<ParserAttribute> attributes)
      Create a symbol with an initial set of attributes.
      Parameters:
      attributes - the attributes
      Throws:
      GrammarException - if the attribute names are not unique
      AttributeException - if an attribute has an invalid value
  • Method Details

    • matches

      public abstract boolean matches(Token input)
      Does this symbol match the specified token?

      This is very like equality, but consider that for some kinds of symbols (for example, tokens that match regular expressions) it isn't really the same as equality.

      Parameters:
      input - The token.
      Returns:
      true if the token matches.
    • matches

      public abstract boolean matches(Symbol input)
      Does this symbol match the specified symbol?
      Parameters:
      input - The symbol.
      Returns:
      true if it is the same symbol as this symbol.