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 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 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)); }