Package org.nineml.coffeegrinder.parser
Class Rule
- java.lang.Object
-
- org.nineml.coffeegrinder.parser.Rule
-
public class Rule extends java.lang.Object
A grammar rule.A grammar rule maps a single
NonterminalSymbol
to zero or moresymbols
(eitherTerminals
or furtherNonterminals
).
-
-
Field Summary
Fields Modifier and Type Field Description RightHandSide
rhs
NonterminalSymbol
symbol
-
Constructor Summary
Constructors Constructor Description Rule(NonterminalSymbol symbol, java.util.List<Symbol> rhs)
Construct a new rule mapping the nonterminal to a sequence of symbols.Rule(NonterminalSymbol symbol, Symbol... rhs)
Construct a new rule mapping the nonterminal to a sequence of symbols.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
epsilonRule()
boolean
equals(java.lang.Object obj)
RightHandSide
getRhs()
The sequence of symbols that comprise the definition of the rule's nonterminal.java.util.List<State>
getSlots()
NonterminalSymbol
getSymbol()
The nonterminal symbol defined by this rule.int
hashCode()
java.lang.String
toString()
Pretty print a node.
-
-
-
Field Detail
-
symbol
public final NonterminalSymbol symbol
-
rhs
public final RightHandSide rhs
-
-
Constructor Detail
-
Rule
public Rule(NonterminalSymbol symbol, Symbol... rhs)
Construct a new rule mapping the nonterminal to a sequence of symbols.If the sequence of symbols is empty or null, then the nonterminal maps to "ε", that is to say, it's allowed to be absent.
- Parameters:
symbol
- The nonterminal.rhs
- The sequence of symbols.
-
Rule
public Rule(NonterminalSymbol symbol, java.util.List<Symbol> rhs)
Construct a new rule mapping the nonterminal to a sequence of symbols.If the sequence of symbols is empty or null, then the nonterminal maps to "ε", that is to say, it's allowed to be absent.
- Parameters:
symbol
- The nonterminal.rhs
- The list of symbols.
-
-
Method Detail
-
getSymbol
public NonterminalSymbol getSymbol()
The nonterminal symbol defined by this rule.- Returns:
- The nonterminal symbol.
-
getRhs
public RightHandSide getRhs()
The sequence of symbols that comprise the definition of the rule's nonterminal.Note: although a rule may be defined with a null "right hand side", this method always returns an empty list in such cases.
- Returns:
- The sequence of symbols.
-
epsilonRule
public boolean epsilonRule()
-
getSlots
public java.util.List<State> getSlots()
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
Pretty print a node.- Overrides:
toString
in classjava.lang.Object
- Returns:
- a string representation of the node.
-
-