Show / Hide Table of Contents

    Class ModifierFormulaParser

    This parser implements the Shunting-yard Algorithm and Reverse Polish Notation to take a formula written like "3 + ( 45 / 3 ) - 4" and parse it down to a single result.

    Inheritance
    Object
    ModifierFormulaParser
    Implements
    IModifierFormulaParser
    IInjectable
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ToString()
    Object.ReferenceEquals(Object, Object)
    Namespace: IdleKit.Gameplay
    Assembly: cs.temp.dll.dll
    Syntax
    public class ModifierFormulaParser : IModifierFormulaParser, IInjectable

    Fields

    _cachedRPNResult

    Declaration
    protected IToken[] _cachedRPNResult
    Field Value
    Type Description
    IToken[]

    _modifierGroupLookup

    Declaration
    protected Dictionary<string, IModifierGroupData> _modifierGroupLookup
    Field Value
    Type Description
    Dictionary<String, IModifierGroupData>

    BASE

    Declaration
    protected static Regex BASE
    Field Value
    Type Description
    Regex

    COMMA

    Declaration
    protected static Regex COMMA
    Field Value
    Type Description
    Regex

    FUNCTION

    Declaration
    protected static Regex FUNCTION
    Field Value
    Type Description
    Regex

    LEFT_PAREN

    Declaration
    protected static Regex LEFT_PAREN
    Field Value
    Type Description
    Regex

    OPERATOR

    Declaration
    protected static Regex OPERATOR
    Field Value
    Type Description
    Regex

    RIGHT_PAREN

    Declaration
    protected static Regex RIGHT_PAREN
    Field Value
    Type Description
    Regex

    VALUE

    Declaration
    protected static Regex VALUE
    Field Value
    Type Description
    Regex

    Methods

    GetPrecedence(String)

    Declaration
    protected virtual int GetPrecedence(string op)
    Parameters
    Type Name Description
    String op
    Returns
    Type Description
    Int32

    GetRPNResult(String)

    Return an array of tokens in Reverse Polish Notation using the Shunting-yard Algorithm.

    Declaration
    protected virtual IToken[] GetRPNResult(string formula)
    Parameters
    Type Name Description
    String formula

    The formula to process. Must contain spaces between values, parentheses and operators.

    Returns
    Type Description
    IToken[]

    Inject(IResolver)

    Declaration
    public void Inject(IResolver resolver)
    Parameters
    Type Name Description
    IResolver resolver

    Parse(String, IModifier[], IModifierGroupData[], Double, Int32)

    Declaration
    public virtual double Parse(string formula, IModifier[] modifiers, IModifierGroupData[] modifierGroupDatas, double baseAmount, int additionalLevels)
    Parameters
    Type Name Description
    String formula
    IModifier[] modifiers
    IModifierGroupData[] modifierGroupDatas
    Double baseAmount
    Int32 additionalLevels
    Returns
    Type Description
    Double

    ParseRPN(IToken[], IModifier[], Double, Int32)

    Given an array of tokens will output a final result.

    Declaration
    protected virtual double ParseRPN(IToken[] tokens, IModifier[] modifiers, double baseAmount, int additionalLevels)
    Parameters
    Type Name Description
    IToken[] tokens

    An array of tokens in Reverse Polish Notation format.

    IModifier[] modifiers

    The IModifier objects that this formula interacts with

    Double baseAmount

    The base amount to be used in the formula

    Int32 additionalLevels

    Additional levels to be passed into IModifierData calculations

    Returns
    Type Description
    Double

    Implements

    IModifierFormulaParser
    IInjectable
    Back to top Copyright © 2020 East Side Games Inc.