Table of Contents

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

Grammar

Kind

The kind of the conflict.

public required LrConflictKind Kind { get; init; }

Property Value

LrConflictKind

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

ProductionHandle

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

ProductionHandle

Exceptions

InvalidOperationException

Kind is not ReduceReduce.

ShiftState

The state to shift to as one of the possible outcomes of a Shift-Reduce conflict.

public int ShiftState { get; init; }

Property Value

int

Exceptions

InvalidOperationException

Kind is not ShiftReduce.

StateIndex

The index of the state with this conflict.

public required int StateIndex { get; init; }

Property Value

int

TerminalOrEndOfInput

The handle to the terminal upon whose encounter the conflict manifests.

public required TokenSymbolHandle TerminalOrEndOfInput { get; init; }

Property Value

TokenSymbolHandle

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 Grammar

The Grammar that the conflict is in.

stateIndex int

The index of the state with the conflict.

reduceProduction ProductionHandle

The production to reduce.

Returns

LrConflict

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 Grammar

The Grammar that the conflict is in.

stateIndex int

The index of the state with the conflict.

terminalOrEndOfInput TokenSymbolHandle

The name of the terminal upon whose encounter the conflict manifests, or default if the ocnflict manifests when encountering the end of input.

reduceProduction ProductionHandle

The first production to reduce.

reduceProduction2 ProductionHandle

The second production to reduce.

Returns

LrConflict

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 Grammar

The Grammar that the conflict is in.

stateIndex int

The index of the state with the conflict.

terminal TokenSymbolHandle

The name of the terminal upon whose encounter the conflict manifests.

shiftState int

The index of the state to shift to.

reduceProduction ProductionHandle

The production to reduce.

Returns

LrConflict

ToString()

Formats the LrConflict to a string.

public override string ToString()

Returns

string

ToString(string?, IFormatProvider?)

Formats the LrConflict to a string, while also supporting localization.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

Unused.

formatProvider IFormatProvider

Used to select the culture to localize the conflict.

Returns

string