Пример #1
0
 def __exit(self):
     return_node = ast.ReturnStmt()
     if self.current_token.tokentype != token.SEMICOLON:
         return_node.return_expr = self.__expr()
     return_node.return_token = self.current_token
     self.__eat(token.SEMICOLON, "expecting ';'")
     return return_node
Пример #2
0
 def __exit(self):
     """<exit> ::= RETURN ( <expr>| E ) SEMICOLON"""
     exitStmt = ast.ReturnStmt()
     exitStmt.return_token = self.current_token
     self.__eat(token.RETURN, "expecting 'return'")
     if self.current_token.tokentype != token.SEMICOLON:
         exitStmt.return_expr = self.__expr()
     self.__eat(token.SEMICOLON, "expecting a ';'")
     return exitStmt
Пример #3
0
 def __exit(self):
     """<exit> ::= RETURN (<expr> | e) SEMICOLON"""
     return_stmt_node = ast.ReturnStmt()
     return_stmt_node.return_token = self.current_token
     self.__eat(token.RETURN, 'expecting a "return" keyword')
     types = [token.LPAREN,token.STRINGVAL, token.INTVAL, token.BOOLVAL]
     types.extend([token.FLOATVAL, token.NIL, token.NEW, token.ID])
     if self.current_token.tokentype in types:
         return_stmt_node.return_expr = self.__expr()
     self.__eat(token.SEMICOLON, 'expecting a ";"')
     return return_stmt_node
Пример #4
0
 def __exit(self):
     return_node = ast.ReturnStmt()
     return_node.return_token = self.current_token
     self.__eat(token.RETURN, 'expecting return')
     types = [
         token.STRINGVAL, token.INTVAL, token.BOOLVAL, token.FLOATVAL,
         token.NIL, token.NEW, token.ID, token.LPAREN
     ]
     if self.current_token.tokentype in types:
         return_node.return_expr = self.__expr()
     self.__eat(token.SEMICOLON, 'expecting semicolon')
     return return_node
Пример #5
0
 def __exit(self, stmt_list_node):
     returnNode = ast.ReturnStmt()
     returnNode.return_token = self.current_token
     self.__eat(token.RETURN, 'expecting return')
     listofexpr = [
         token.STRINGVAL, token.INTVAL, token.BOOLVAL, token.FLOATVAL,
         token.NIL, token.NEW, token.LPAREN, token.ID
     ]
     if self.current_token.tokentype in listofexpr:
         returnNode.return_expr = self.__expr()
     self.__eat(token.SEMICOLON, 'expecting ;')
     stmt_list_node.stmts.append(returnNode)
Пример #6
0
 def __exit(self):
     """<exit> ::= RETURN ( <expr> | e ) SEMICOLON"""
     return_stmt_node = ast.ReturnStmt()
     exprhelp = [
         token.STRINGVAL, token.INTVAL, token.BOOLVAL, token.FLOATVAL,
         token.NIL, token.NEW, token.ID, token.LPAREN
     ]
     return_stmt_node.return_token = self.current_token
     self.__eat(token.RETURN, 'expecting "return"')
     if (self.current_token.tokentype in exprhelp):
         return_stmt_node.return_expr = self.__expr()
     self.__eat(token.SEMICOLON, 'expecting ";"')
     return return_stmt_node
Пример #7
0
 def __exit(self):
     # print("exit: " + str(self.current_token))
     return_stmt_node = ast.ReturnStmt()
     # the next line just contains the 'return' keyword
     return_stmt_node.return_token = self.current_token # this is useless but part of the documentation
     self.__advance() # eat RETURN (we already know from bstmt)
     if (self.current_token.tokentype == token.STRINGVAL or # check for expr -> rvalue...
             self.current_token.tokentype == token.INTVAL or
             self.current_token.tokentype == token.BOOLVAL or
             self.current_token.tokentype == token.FLOATVAL or
             self.current_token.tokentype == token.NIL or
             self.current_token.tokentype == token.NEW or
             self.current_token.tokentype == token.ID or
             self.current_token.tokentype == token.LPAREN): # check for expr -> LPAREN
         return_stmt_node.return_expr = self.__expr()
     self.__eat(token.SEMICOLON, 'expected ";"')
     return return_stmt_node
Пример #8
0
    def __exit(self):
        """<exit> ::= RETURN ( <expr> | e ) SEMICOLON"""
        exprStarts = [
            token.STRINGVAL, token.INTVAL, token.BOOLVAL, token.FLOATVAL,
            token.NIL, token.LPAREN, token.ID
        ]

        return_stmt = ast.ReturnStmt()
        return_stmt.return_token = self.current_token
        self.__eat(token.RETURN, "expected 'return'")

        if self.current_token.tokentype in exprStarts:
            return_stmt.return_expr = self.__expr()
        else:
            pass

        self.__eat(token.SEMICOLON, "expected ';'")

        return return_stmt