def return_statement(self): self.expect(T.RETURN) if self.peek().type == T.SEMICOLON: expr = None expr = self.expr() self.expect(T.SEMICOLON) return ast.ReturnStmt(expr)
def __exit(self): return_stmt_node = ast.ReturnStmt() return_stmt_node.return_token = self.current_token self.__advance() possible_tokens = [ token.STRINGVAL, token.INTVAL, token.BOOLVAL, token.FLOATVAL, token.NIL, token.NEW, token.ID, token.LPAREN ] curr_token = self.current_token.tokentype if curr_token in possible_tokens: return_stmt_node.return_expr = self.__expr() # return; ??? self.__eat(token.SEMICOLON) return return_stmt_node
def p_returnstmt(p): '''returnstmt : TKRETURN arith_expr ';' ''' p[0] = ast.ReturnStmt(p[2]).addloc(p.lineno(1))
def p_stmt_return(p): 'stmt : RETURN expr_opt SEMICOLON' p[0] = ast.ReturnStmt(p[2], p.lineno(1))