def _consumeNumber(self, stream: StringStream) -> Optional[NumberExpression]: if not self._can_consumeDigit(stream): return None token = stream.next() while self._can_consumeDigit(stream): token += stream.next() return token
def parse(self, stream: StringStream) -> Optional[NumberExpression]: if not self.can_consume(stream): return None token: str = stream.peek() if token.isspace(): stream.next() return self.parse(stream) isNegative = self._isNegativeSign(token) if isNegative: stream.next() numberToken = self._consumeNumber(stream) return NumberExpression(numberToken, isNegative)
def parse(self, stream: StringStream) -> Optional[Expression]: while stream.has_chars() and not stream.peek() == ')': if not self._can_consume(stream): stream.next() continue if self._consume_number(stream): continue self._consume_operator(stream) if stream.peek() == '(': stream.next() self._evaluate_bracket_expression(stream) return self._tree.create_expression()
def parse(self, stream: StringStream) -> Optional[Operator]: if not self.can_consume(stream): return None token: str = stream.next() if token == '+': return AddOperator() elif token == '-': return SubtractOperator() elif token == '*': return MultiplyOperator() elif token == '/': return DivideOperator() elif token.isspace(): return self.parse(stream)