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)); }
private Variable[] ReadVariables(LexemEnumerator enumerator) { var resultVariables = new List <Variable>(); while (enumerator.IsHasValue) { resultVariables.Add(ReadNextVariable(enumerator)); } return(resultVariables.ToArray()); }
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)); }
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)); }
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)); }