bool parseExpCandidate(ref string expCandidate, IList <ExpAtom> sequence) { int position = 0; bool numberNow = true; // what to read from string: number or operation Match match; ExpAtom expAtom; Console.WriteLine("Parsing expression candidate '{0}'", expCandidate); do { Console.WriteLine("Retrieving first {1} from '{0}'", expCandidate.Substring(position), (numberNow ? "numeric" : "operation")); match = (numberNow ? _regExpNumber : _regExpOperation).Match(expCandidate.Substring(position)); if (!match.Success) { Console.WriteLine("Matching failed"); break; } Console.WriteLine("Matched substring '{0}'", match.Value); if (2 < match.Groups.Count || 1 != match.Groups[1].Captures.Count) { Console.WriteLine("Wrong match groups or captures count"); break; } Console.WriteLine("Captured substring '{0}'", match.Groups[1].Captures[0].Value); expAtom = new ExpAtom(match.Groups[1].Captures[0].Value, (numberNow ? ExpAtomType.Numeric : ExpAtomType.Operation)); if (ExpAtomType.None == expAtom.AtomType) { Console.WriteLine("Convertation error"); break; } sequence.Add(expAtom); position += match.Length; numberNow ^= true; } while(position < expCandidate.Length); return(!numberNow && position == expCandidate.Length); }
ExpAtom simplifyTriple(ExpAtom value1, ExpAtom operation, ExpAtom value2) { return(new ExpAtom(performCalculation(value1.Value, operation.Operation, value2.Value))); }