def comp_expr(self): res = ParseResult() if self.current_tok.matches(token.T_KEYWORD, 'not'): op_tok = self.current_tok res.register_advancement() self.advance() node = res.register(self.comp_expr()) if res.error: return res return res.success(nodes.UnaryOpNode(op_tok, node)) node = res.register( self.bin_op(self.arithm_expr, (token.T_EE, token.T_NE, token.T_LT, token.T_GT, token.T_LTE, token.T_GTE))) if res.error: return res.failure( errors.InvalidSyntaxError( self.current_tok.pos_start, self.current_tok.pos_end, "Expected int or float, identifier, '+', '-', '(', '[' or 'not'" )) return res.success(node)
def factor(self): res = ParseResult() tok = self.current_tok if tok.type in (token.T_PLUS, token.T_MINUS): res.register_advancement() self.advance() factor = res.register(self.factor()) if res.error: return res return res.success(nodes.UnaryOpNode(tok, factor)) return self.power()