public override void Parse(IList <char> input)
        {
            Term = new TermExpression();
            Term.Parse(input);

            if (input.Count == 0)
            {
                return;
            }

            if (input[0] != '-' && input[0] != '+')
            {
                return;
            }

            if (input[0] == '-')
            {
                IsSubtraction = true;
            }

            input.RemoveAt(0);
            if (input.Count == 0)
            {
                throw new UnexpectedTokenException();
            }

            Expression = new ExpressionsExpression();
            Expression.Parse(input);
        }
Beispiel #2
0
        public override void Parse(IList <char> input)
        {
            if (input[0] == '(')
            {
                input.RemoveAt(0);
                if (input.Count == 0)
                {
                    throw new UnexpectedTokenException();
                }

                Expression = new ExpressionsExpression();
                Expression.Parse(input);

                if (input.Count == 0)
                {
                    throw new UnexpectedTokenException();
                }

                if (input[0] != ')')
                {
                    throw new UnexpectedTokenException(input[0].ToString(), "')'");
                }

                input.RemoveAt(0);
            }
            else
            {
                //var numberStr = "";

                //do
                //{
                //    numberStr += input[0];
                //    input.RemoveAt(0);
                //} while (input.Count > 0 && char.IsDigit(input[0]));

                //Number = double.Parse(numberStr);

                var numberStr = "";
                if (input[0] == '-')
                {
                    numberStr += '-';
                    input.RemoveAt(0);
                }
                if (input.Count == 0)
                {
                    throw new UnexpectedTokenException();
                }

                do
                {
                    numberStr += input[0];
                    input.RemoveAt(0);
                } while (input.Count > 0 && (char.IsDigit(input[0]) || input[0] == '.'));

                if (double.TryParse(numberStr, out double temp))
                {
                    Number = temp;
                }
                else
                {
                    throw new UnexpectedTokenException(numberStr);
                }
            }
        }