Class Nonterminal<T>
Represents a nonterminal symbol in a grammar to be built that produces a value, and allows setting its productions after its creation.
public sealed class Nonterminal<T> : IGrammarSymbol<T>, IGrammarBuilder<T>, IGrammarSymbol, IGrammarBuilder
Type Parameters
T
The type of values the nonterminal will produce.
- Inheritance
-
Nonterminal<T>
- Implements
- Extension Methods
Remarks
In Farkle, builder objects are usually immutable. This exception exists to support defining recursive nonterminals.
Properties
Name
The symbol's name.
public string Name { get; }
Property Value
Remarks
This value is used only for diagnostic and documentation purposes and does not affect the grammar's behavior when parsing. A grammar may contain multiple symbols with the same name.
Methods
SetProductions(params IProduction<T>[])
Sets the productions of this nonterminal.
public void SetProductions(params IProduction<T>[] productions)
Parameters
productions
IProduction<T>[]An array with the productions to set.
Remarks
This function and its overloads must be called exactly once, and before the nonterminal is used in building a grammar.
Exceptions
- ArgumentException
productions
is empty.- InvalidOperationException
The productions have already been successfully set.
SetProductions(params ImmutableArray<IProduction<T>>)
Sets the productions of this nonterminal.
public void SetProductions(params ImmutableArray<IProduction<T>> productions)
Parameters
productions
ImmutableArray<IProduction<T>>The productions to set.
Remarks
This function and its overloads must be called exactly once, and before the nonterminal is used in building a grammar.
Exceptions
- ArgumentException
productions
is empty.- InvalidOperationException
The productions have already been successfully set.