示例#1
0
        public static IMathExpressionParser CreateParser(IOperationFactory operationFactory)
        {
            _operationFactory = operationFactory ?? throw new ArgumentNullException(nameof(operationFactory));

            var highPriorityParser = new MathExpressionParser(operationFactory.CreateHighPriorityOperation, ParseUnary);
            var lowPriorityParser  = new MathExpressionParser(operationFactory.CreateLowPriorityOperation, highPriorityParser.Parse);

            _expressionParser = lowPriorityParser;

            return(lowPriorityParser);
        }
        public IExpression ParseExpression(ITokenizer tokenizer)
        {
            if (tokenizer == null)
            {
                throw new ArgumentNullException(nameof(tokenizer));
            }

            tokenizer.Init();

            var expressionParser = MathExpressionParser.CreateParser(_operationFactory);

            var expression = expressionParser.Parse(tokenizer);

            tokenizer.CurrentToken.EnsureEndOfFileSymbol();

            return(expression);
        }