private void PushToStack(ParseOperation parseOperation) { if (_parseOperationStack.Count > 0 && _parseOperationStack.Peek().Priority >= parseOperation.Priority) { _parseSequence.Enqueue(new Parse(_parseOperationStack.Pop())); PushToStack(parseOperation); } else { _parseOperationStack.Push(parseOperation); } }
public void Add(Token token) { switch (token.TokenType) { case TokenType.PRINT: ReleaseParseOperationStack(); _parseSequence.Enqueue(new Parse(token)); break; case TokenType.DIGIT: case TokenType.VAR: case TokenType.CREATE_LIST: case TokenType.CREATE_HASH_SET: case TokenType.ASYNC: _parseSequence.Enqueue(new Parse(token)); break; case TokenType.LB_S: _parseOperationStack.Push(new ParseOperation(token)); break; case TokenType.RB_S: for (ParseOperation stackParseOperation = _parseOperationStack.Pop(); stackParseOperation.parseType != ParseType.LB_S; stackParseOperation = _parseOperationStack.Pop()) { _parseSequence.Enqueue(new Parse(stackParseOperation)); } _parseSequence.Enqueue(new Parse("I", ParseType.INDEX)); break; case TokenType.LB: _parseOperationStack.Push(new ParseOperation(token)); break; case TokenType.RB: for (ParseOperation stackParseOperation = _parseOperationStack.Pop(); stackParseOperation.parseType != ParseType.LB; stackParseOperation = _parseOperationStack.Pop()) { _parseSequence.Enqueue(new Parse(stackParseOperation)); } break; default: ParseOperation parseOperation = new ParseOperation(token); PushToStack(parseOperation); break; } }
public Parse(ParseOperation parseOperation) { ParseType = parseOperation.parseType; Value = parseOperation.Value; }