Class LrConflict
- Namespace
- Farkle.Diagnostics.Builder
- Assembly
- Farkle.dll
Represents a conflict in an LR parser state machine. A conflict manifests when the parser can take multiple possible actions when encountering a terminal.
public sealed class LrConflict : ISpanFormattable, IFormattable
- Inheritance
-
LrConflict
- Implements
Properties
Grammar
The grammar whose LR state machine has this conflict.
public required Grammar Grammar { get; init; }
Property Value
Kind
The kind of the conflict.
public required LrConflictKind Kind { get; init; }
Property Value
ReduceProduction
The handle to the production to reduce, as one of the possible outcomes of the conflict.
public required ProductionHandle ReduceProduction { get; init; }
Property Value
ReduceProduction2
The handle to the alternative production to reduce, as one of the possible outcomes of a Reduce-Reduce conflict.
public ProductionHandle ReduceProduction2 { get; init; }
Property Value
Exceptions
ShiftState
The state to shift to as one of the possible outcomes of a Shift-Reduce conflict.
public int ShiftState { get; init; }
Property Value
Exceptions
- InvalidOperationException
Kind is not ShiftReduce.
StateIndex
The index of the state with this conflict.
public required int StateIndex { get; init; }
Property Value
TerminalOrEndOfInput
The handle to the terminal upon whose encounter the conflict manifests.
public required TokenSymbolHandle TerminalOrEndOfInput { get; init; }
Property Value
Remarks
This property can have no value (as determined by HasValue) if the conflict manifests when the parser reaches the end of the input. This can never be the case in ShiftReduce conflicts, and is always the case in AcceptReduce conflicts.
Methods
CreateAcceptReduce(Grammar, int, ProductionHandle)
Creates an LrConflict representing an Accept-Reduce conflict.
public static LrConflict CreateAcceptReduce(Grammar grammar, int stateIndex, ProductionHandle reduceProduction)
Parameters
grammar
GrammarThe Grammar that the conflict is in.
stateIndex
intThe index of the state with the conflict.
reduceProduction
ProductionHandleThe production to reduce.
Returns
CreateReduceReduce(Grammar, int, TokenSymbolHandle, ProductionHandle, ProductionHandle)
Creates an LrConflict representing a Reduce-Reduce conflict.
public static LrConflict CreateReduceReduce(Grammar grammar, int stateIndex, TokenSymbolHandle terminalOrEndOfInput, ProductionHandle reduceProduction, ProductionHandle reduceProduction2)
Parameters
grammar
GrammarThe Grammar that the conflict is in.
stateIndex
intThe index of the state with the conflict.
terminalOrEndOfInput
TokenSymbolHandleThe name of the terminal upon whose encounter the conflict manifests, or default if the ocnflict manifests when encountering the end of input.
reduceProduction
ProductionHandleThe first production to reduce.
reduceProduction2
ProductionHandleThe second production to reduce.
Returns
CreateShiftReduce(Grammar, int, TokenSymbolHandle, int, ProductionHandle)
Creates an LrConflict representing a Shift-Reduce conflict.
public static LrConflict CreateShiftReduce(Grammar grammar, int stateIndex, TokenSymbolHandle terminal, int shiftState, ProductionHandle reduceProduction)
Parameters
grammar
GrammarThe Grammar that the conflict is in.
stateIndex
intThe index of the state with the conflict.
terminal
TokenSymbolHandleThe name of the terminal upon whose encounter the conflict manifests.
shiftState
intThe index of the state to shift to.
reduceProduction
ProductionHandleThe production to reduce.
Returns
ToString()
Formats the LrConflict to a string.
public override string ToString()
Returns
ToString(string?, IFormatProvider?)
Formats the LrConflict to a string, while also supporting localization.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
format
stringUnused.
formatProvider
IFormatProviderUsed to select the culture to localize the conflict.