/// <summary> /// Combines an optree with a term using the given operator. /// </summary> public static _OpTree Combine(_OpTree Left, Operator Operator, Expression Right) { if (Left.Operator == null || Left.Operator.Precedence >= Operator.Precedence) return new _OpTree(Operator, Left, new _OpTree(Right)); else return new _OpTree(Left.Operator, Left.Left, Combine(Left.Right, Operator, Right)); }
/// <summary> /// Adds an operator to the available set of operators. /// </summary> public static void Add(Operator Operator) { MaxOperatorLength = Math.Max(MaxOperatorLength, Operator.Name.Length); Map[Operator.Name] = Operator; }
public _OpTree(Operator Operator, _OpTree Left, _OpTree Right) { this.Operator = Operator; this.Left = Left; this.Right = Right; }
/// <summary> /// Tries parsing an operator in the given text. /// </summary> public static bool AcceptOperator(string Text, ref int Index, ref Operator Operator) { bool found = false; int sindex = Index; int maxlen = Math.Min(Operator.MaxOperatorLength, Text.Length - Index); for (int t = 1; t <= maxlen; t++) { string optext = Text.Substring(sindex, t); Operator op; if (Operator.Map.TryGetValue(optext, out op)) { Index = sindex + t; Operator = op; found = true; } } return found; }