public override Node VisitFunc([NotNull] FormulaGrammerParser.FuncContext context)
        {
            var functionNameToken = context.IDENTIFIER().Symbol;

            if (this.configuration.IsFunctionsSupportDisabled)
            {
                ParsingException.ThrowInvalidTokenException(functionNameToken);
            }

            var functionName = functionNameToken.Text;

            var parameters = new List <Node>();
            var idxExp     = 0;

            FormulaGrammerParser.ExpressionContext exp;
            while ((exp = context.expression(idxExp++)) != null)
            {
                parameters.Add(this.Visit(exp));
            }

            if (!this.configuration.IsFunctionNameValidationDisabled && !this.configuration.HasFunction(functionName, parameters.Count))
            {
                ParsingException.ThrowUnknownFunctionException(functionNameToken);
            }

            return(new FunctionNode(functionName, parameters.ToArray()));
        }
        public override Node VisitScientificNumber([NotNull] FormulaGrammerParser.ScientificNumberContext context)
        {
            if (this.configuration.IsScientificNotationSupportDisabled)
            {
                ParsingException.ThrowInvalidTokenException(context.SCIENTIFIC_NUMBER().Symbol);
            }

            var scientificNumber = context.SCIENTIFIC_NUMBER().Symbol.Text;

            return(new NumberNode(double.Parse(scientificNumber)));
        }
        public override Node VisitAtom([NotNull] FormulaGrammerParser.AtomContext context)
        {
            var expression = context.expression();

            if (expression != null)
            {
                if (this.configuration.IsBracketSupportDisabled)
                {
                    ParsingException.ThrowInvalidTokenException(context.LPAREN().Symbol);
                }

                return(new BracketedNode(this.VisitExpression(expression)));
            }

            return(base.VisitAtom(context));
        }
        public override Node VisitPowExpression([NotNull] FormulaGrammerParser.PowExpressionContext context)
        {
            int idxExponent = 0;

            if (this.configuration.IsPowSupportDisabled)
            {
                ParsingException.ThrowInvalidTokenException(context.POW(0).Symbol);
            }

            var signedAtom = context.signedAtom(idxExponent++);
            var node       = this.Visit(signedAtom);

            while ((signedAtom = context.signedAtom(idxExponent++)) != null)
            {
                var exponent = this.Visit(signedAtom);
                node = new PowerNode(node, exponent);
            }

            return(node);
        }
        public override Node VisitVariable([NotNull] FormulaGrammerParser.VariableContext context)
        {
            var variableNameToken = context.IDENTIFIER().Symbol;

            if (this.configuration.HasConstant(variableNameToken.Text))
            {
                return(new ConstantNode(variableNameToken.Text));
            }

            if (this.configuration.IsVariablesSupportDisabled)
            {
                ParsingException.ThrowInvalidTokenException(variableNameToken);
            }

            var variableName = variableNameToken.Text;

            if (!this.configuration.IsVariableNameValidationDisabled && !this.configuration.HasVariable(variableName))
            {
                ParsingException.ThrowUnknownVariableException(variableNameToken);
            }

            return(new VariableNode(variableName));
        }