private void Hold(SymbolToken val) { _heldInput.Add(val); if (val.Type == SymbolType.OpenBracket) { _parentheses++; } if (val.Type == SymbolType.CloseBracket) { _parentheses--; } // Unary operations are the only case where an open parenthesis // that applies to the negation may come as the second token. // Unparsed negations also count, handled below as a special case // (since they do not require parentheses) if (_heldInput.Count == 1 && val.Type.IsUnaryOperation()) { return; } // be careful here: new, unparsed subtractions can be continued // negation tokens. Be sure to handle those! if (_parentheses == 0 && val.Type != SymbolType.Subtraction) { var np = new NegationProcessor(_heldInput); Output(np.PumpAll()); Output(SymbolToken.CloseBracket); _heldInput = new List <SymbolToken>(); _holdInput = false; } }
public static List <SymbolToken> Parse(string expression, VariableContext context) { var pipe1 = new StringToPrimitiveTokenPipe(expression, context); var pipe2 = new MatchAllParenthesesProcessor(pipe1); var pipe3 = new NegationProcessor(pipe2); var pipe4 = new RedundantParenthesesProcessor(pipe3); var pipe5 = new TokenValidater(pipe4); return(pipe5.PumpAll()); }
protected override void Finish() { if (_heldInput.Count == 0) { return; } var np = new NegationProcessor(_heldInput); Output(np.PumpAll()); Output(SymbolToken.CloseBracket); _parentheses = 0; _heldInput = new List <SymbolToken>(); _lastOutput = SymbolToken.OpenBracket; _holdInput = false; }