Esempio n. 1
0
    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)
Esempio n. 2
0
 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
Esempio n. 3
0
def p_returnstmt(p):
    '''returnstmt : TKRETURN arith_expr ';' '''
    p[0] = ast.ReturnStmt(p[2]).addloc(p.lineno(1))
Esempio n. 4
0
def p_stmt_return(p):
    'stmt : RETURN expr_opt SEMICOLON'
    p[0] = ast.ReturnStmt(p[2], p.lineno(1))