Table of Contents

Interface IOperatorProvider

Namespace
RandomizerCore.StringParsing
Assembly
RandomizerCore.dll

Defines domain-specific operator definitions.

public interface IOperatorProvider

Remarks

The "binding power" concept was borrowed from this explainer of Pratt Parsing: https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html. It is essentially an alternative way to think about precedence, but gives a natural way to explain biased associativity.

In short, each operator has a distinct left and right binding power. When looking at B in the expression A <op1> B <op2> C, you see whether the right BP of op1 is higher or lower than the left BP of op2 to see which operator has the stronger ability to "pull" or "bind" B into its expression. Left and right BP can be (and should be) asymmetric to give a well-defined preference for the case where op1 and op2 are the same operator (or 2 operators at the same precedence level).

Methods

GetAllOperators()

Get all operators defined by this provider.

IReadOnlyCollection<string> GetAllOperators()

Returns

IReadOnlyCollection<string>

InfixBindingPower(string)

Get the left and right binding powers of the operator if that operator is a known infix operator, otherwise null

(int, int)? InfixBindingPower(string op)

Parameters

op string

Returns

(int, int)?

PostfixBindingPower(string)

Get the binding power of the operator if that operator is a known postfix operator, otherwise null

int? PostfixBindingPower(string op)

Parameters

op string

Returns

int?

PrefixBindingPower(string)

Get the binding power of the operator if that operator is a known prefix operator, otherwise null

int? PrefixBindingPower(string op)

Parameters

op string

Returns

int?