public Expression(List <Token> polishNotationTokens, ExpressionParser <T> expressionParser, string expression)
 {
     parser             = expressionParser;
     originalExpression = expression;
     rootNode           = CreateTree(polishNotationTokens);
 }
        public void Setup()
        {
            parser = new ExpressionParser <float>();

            // Plus Symbol
            ExpressionParser <float> .Symbol plusSymbol = new ExpressionParser <float> .Symbol();

            plusSymbol.Name          = "+";
            plusSymbol.Type          = SymbolType.Operator;
            plusSymbol.Precedence    = 1;
            plusSymbol.RegexOverride = "\\+";
            plusSymbol.binaryFunc    = (left, right) => left + right;
            parser.WithSymbol(plusSymbol);

            // Minus Symbol
            ExpressionParser <float> .Symbol minusSymbol = new ExpressionParser <float> .Symbol();

            minusSymbol.Name          = "-";
            minusSymbol.Type          = SymbolType.Operator;
            minusSymbol.Precedence    = 2;
            minusSymbol.RegexOverride = "\\-";
            minusSymbol.unaryFunc     = (val) => - val;
            minusSymbol.binaryFunc    = (left, right) => left - right;
            parser.WithSymbol(minusSymbol);

            // Multiply Symbol
            ExpressionParser <float> .Symbol multSymbol = new ExpressionParser <float> .Symbol();

            multSymbol.Name          = "*";
            multSymbol.Type          = SymbolType.Operator;
            multSymbol.Precedence    = 3;
            multSymbol.RegexOverride = "\\*";
            multSymbol.binaryFunc    = (left, right) => left * right;
            parser.WithSymbol(multSymbol);

            // Divide Symbol
            ExpressionParser <float> .Symbol divideSymbol = new ExpressionParser <float> .Symbol();

            divideSymbol.Name          = "/";
            divideSymbol.Type          = SymbolType.Operator;
            divideSymbol.Precedence    = 4;
            divideSymbol.RegexOverride = "\\/";
            divideSymbol.binaryFunc    = (left, right) => left / right;
            parser.WithSymbol(divideSymbol);

            // Open Parenthesis
            ExpressionParser <float> .Symbol openParenthesis = new ExpressionParser <float> .Symbol();

            openParenthesis.Name          = "(";
            openParenthesis.Type          = SymbolType.OpenParenthesis;
            openParenthesis.RegexOverride = "\\(";
            parser.WithSymbol(openParenthesis);

            // Close Parenthesis
            ExpressionParser <float> .Symbol closeParenthesis = new ExpressionParser <float> .Symbol();

            closeParenthesis.Name          = ")";
            closeParenthesis.Type          = SymbolType.CloseParenthesis;
            closeParenthesis.RegexOverride = "\\)";
            parser.WithSymbol(closeParenthesis);

            // Interpret literals.
            parser.LiteralParser = (val) => float.Parse(val);
        }