Ejemplo n.º 1
0
        private Summand CreateSummand(string lexem)
        {
            float coefficient = 1.0f;

            Variable[] variables = null;

            using (var lexemEnumerator = new LexemEnumerator(lexem))
            {
                while (lexemEnumerator.MoveNext())
                {
                    if (lexemEnumerator.Current == Symbol.Minus)
                    {
                        coefficient *= -1;
                    }

                    if (char.IsDigit(lexemEnumerator.Current))
                    {
                        coefficient *= ReadNextFloatDigit(lexemEnumerator);
                    }

                    if (lexemEnumerator.IsHasValue && char.IsLetter(lexemEnumerator.Current))
                    {
                        variables = ReadVariables(lexemEnumerator);
                    }
                }
            }
            return(new Summand(variables, coefficient));
        }
Ejemplo n.º 2
0
        private Variable[] ReadVariables(LexemEnumerator enumerator)
        {
            var resultVariables = new List <Variable>();

            while (enumerator.IsHasValue)
            {
                resultVariables.Add(ReadNextVariable(enumerator));
            }

            return(resultVariables.ToArray());
        }
Ejemplo n.º 3
0
        private Variable ReadNextVariable(LexemEnumerator enumerator)
        {
            var variableLexem = enumerator.Current;

            if (enumerator.MoveNext() &&
                enumerator.Current == Symbol.DegreeSymbol)
            {
                enumerator.MoveNext();
                var degree = ReadNextIntDigit(enumerator);

                return(new Variable(variableLexem, degree));
            }

            return(new Variable(variableLexem));
        }
Ejemplo n.º 4
0
        private int ReadNextIntDigit(LexemEnumerator enumerator)
        {
            var lexem = enumerator.Current.ToString();

            while (enumerator.MoveNext())
            {
                if (char.IsDigit(enumerator.Current))
                {
                    lexem += enumerator.Current;
                }
                else
                {
                    break;
                }
            }
            return(int.Parse(lexem));
        }
Ejemplo n.º 5
0
        private float ReadNextFloatDigit(LexemEnumerator enumerator)
        {
            var lexem = enumerator.Current.ToString();

            while (enumerator.MoveNext())
            {
                var ch = enumerator.Current;
                if (char.IsDigit(ch) || ch == Symbol.DotSeparator)
                {
                    lexem += ch;
                }
                else
                {
                    break;
                }
            }
            return(ParseToFloat(lexem));
        }