def __bstmt(self): """<bstmt> ::= <vdecl> | <assign> | <cond> | <while> | <expr> SEMICOLON | <exit>""" exprStarts = [ token.STRINGVAL, token.INTVAL, token.BOOLVAL, token.FLOATVAL, token.NIL, token.LPAREN, token.NEW, token.ID ] bstmt = None if self.__tokenIs(token.VAR): bstmt = self.__vdecl() elif self.__tokenIs(token.SET): bstmt = self.__assign() elif self.__tokenIs(token.IF): bstmt = self.__cond() elif self.__tokenIs(token.WHILE): bstmt = self.__while() elif self.current_token.tokentype in exprStarts: bstmt = ast.ExprStmt() bstmt.expr = self.__expr() self.__eat(token.SEMICOLON, "expected ';'") else: bstmt = self.__exit() return bstmt
def __bstmt(self): if self.current_token.tokentype == token.VAR: return self.__vdecl() elif self.current_token.tokentype == token.SET: return self.__assign() elif self.current_token.tokentype == token.IF: return self.__cond() elif self.current_token.tokentype == token.RETURN: return self.__exit() elif self.current_token.tokentype == token.WHILE: return self.__while() else: expr_stmt = ast.ExprStmt() expr_stmt.expr = self.__expr() self.__eat(token.SEMICOLON, 'expecting semicolon') return expr_stmt
def __bstmt(self, stmt_list_node): if self.current_token.tokentype == token.VAR: self.__vdecl(stmt_list_node.stmts) elif self.current_token.tokentype == token.SET: self.__assign(stmt_list_node) elif self.current_token.tokentype == token.IF: self.__cond(stmt_list_node) elif self.current_token.tokentype == token.WHILE: self.__while(stmt_list_node) elif self.current_token.tokentype == token.RETURN: self.__exit(stmt_list_node) else: exprStmtNode = ast.ExprStmt() exprStmtNode.expr = self.__expr() stmt_list_node.stmts.append(exprStmtNode) self.__eat(token.SEMICOLON, 'expecting semicolon')
def __bstmt(self): """<bstmt> ::= <vdecl> | <assign> | <cond> | <while> | <expr> SEMICOLON | <exit>""" if self.current_token.tokentype == token.VAR: return self.__vdecl() elif self.current_token.tokentype == token.SET: return self.__assign() elif self.current_token.tokentype == token.IF: return self.__cond() elif self.current_token.tokentype == token.WHILE: return self.__while() elif self.current_token.tokentype == token.RETURN: return self.__exit() else: temp_expr_node = ast.ExprStmt() temp_expr_node.expr = self.__expr() self.__eat(token.SEMICOLON, 'expecting a ";"') return temp_expr_node
def __bstmt(self): # print("bstmt: " + str(self.current_token)) if self.current_token.tokentype == token.VAR: return self.__vdecl() # return VarDeclStmt node elif self.current_token.tokentype == token.SET: return self.__assign() # return AssignStmt node elif self.current_token.tokentype == token.IF: return self.__cond() # return IfStmt node elif self.current_token.tokentype == token.WHILE: return self.__while() # return WhileStmt node elif self.current_token.tokentype == token.RETURN: return self.__exit() # return ReturnStmt node else: expr_stmt_node = ast.ExprStmt() expr_stmt_node.expr = self.__expr() self.__eat(token.SEMICOLON, 'expected ";"') return expr_stmt_node # return ExprStmt node