def __rvalue(self, exprNode): if self.current_token.tokentype == token.STRINGVAL: exprNode.term = ast.SimpleRValue() exprNode.term.val = self.current_token self.__advance() elif self.current_token.tokentype == token.INTVAL: exprNode.term = ast.SimpleRValue() exprNode.term.val = self.current_token self.__advance() elif self.current_token.tokentype == token.BOOLVAL: exprNode.term = ast.SimpleRValue() exprNode.term.val = self.current_token self.__advance() elif self.current_token.tokentype == token.FLOATVAL: exprNode.term = ast.SimpleRValue() exprNode.term.val = self.current_token self.__advance() elif self.current_token.tokentype == token.NIL: exprNode.term = ast.SimpleRValue() exprNode.term.val = self.current_token self.__advance() elif self.current_token.tokentype == token.NEW: self.__advance() exprNode.term = ast.NewRValue() exprNode.term.struct_type = self.current_token self.__eat(token.ID, 'expecting id') else: self.__idrval(exprNode)
def __rvalue(self): """<rvalue> ::= STRING | INT | BOOL | FLOAT | NIL | NEW ID | <idrval>""" if (self.current_token.tokentype == token.STRINGVAL): simple_r_value_node = ast.SimpleRValue() simple_r_value_node.val = self.current_token self.__advance() return simple_r_value_node elif (self.current_token.tokentype == token.INTVAL): simple_r_value_node = ast.SimpleRValue() simple_r_value_node.val = self.current_token self.__advance() return simple_r_value_node elif (self.current_token.tokentype == token.BOOLVAL): simple_r_value_node = ast.SimpleRValue() simple_r_value_node.val = self.current_token self.__advance() return simple_r_value_node elif (self.current_token.tokentype == token.FLOATVAL): simple_r_value_node = ast.SimpleRValue() simple_r_value_node.val = self.current_token self.__advance() return simple_r_value_node elif (self.current_token.tokentype == token.NIL): simple_r_value_node = ast.SimpleRValue() simple_r_value_node.val = self.current_token self.__advance() return simple_r_value_node elif (self.current_token.tokentype == token.NEW): new_r_value_node = ast.NewRValue() self.__advance() new_r_value_node.struct_type = self.current_token self.__eat(token.ID, 'expecting "ID"') return new_r_value_node else: return self.__idrval()
def __rvalue(self): """<rvalue> ::= STRINGVAL | INTVAL | BOOLVAL | FLOATVAL | NIL | NEW ID |<idrval>""" temp = self.current_token.tokentype rStmt = ast.SimpleRValue() rStmt.val = self.current_token if temp == token.STRINGVAL: self.__advance() elif temp == token.INTVAL: self.__advance() elif temp == token.BOOLVAL: self.__advance() elif temp == token.FLOATVAL: self.__advance() elif temp == token.NIL: self.__advance() elif temp == token.NEW: self.__advance() rStmt = ast.NewRValue() rStmt.struct_type = self.current_token self.__eat(token.ID, "expecting an id") else: rStmt = self.__idrval() #rStmt = ast.CallRValue() #rStmt.fun = self.current_token #self.__idrval(rStmt) return rStmt
def __rvalue(self): # this is the one exception I made to advancing # before calling the function simple_rval_node = ast.SimpleRValue() if self.current_token.tokentype == token.NIL: simple_rval_node.val = self.current_token self.__advance() return simple_rval_node elif self.current_token.tokentype == token.NEW: self.__advance() new_rval_node = ast.NewRValue() new_rval_node.struct_type = self.current_token self.__eat(token.ID, "expecting an ID") return new_rval_node elif self.current_token.tokentype == token.STRINGVAL: simple_rval_node.val = self.current_token self.__advance() return simple_rval_node elif self.current_token.tokentype == token.INTVAL: simple_rval_node.val = self.current_token self.__advance() return simple_rval_node elif self.current_token.tokentype == token.BOOLVAL: simple_rval_node.val = self.current_token self.__advance() return simple_rval_node elif self.current_token.tokentype == token.FLOATVAL: simple_rval_node.val = self.current_token self.__advance() return simple_rval_node else: return self.idrval()
def __rvalue(self): rvals = [ token.STRINGVAL, token.INTVAL, token.BOOLVAL, token.FLOATVAL, token.NIL ] if self.current_token.tokentype in rvals: simple_rval_node = ast.SimpleRValue() simple_rval_node.val = self.current_token self.__advance() return simple_rval_node elif self.current_token.tokentype == token.NEW: self.__advance() new_rval_node = ast.NewRValue() new_rval_node.struct_type = self.current_token self.__eat(token.ID, 'expecting ID') return new_rval_node else: return self.__idrval()
def __rvalue(self): # print("rvalue: " + str(self.current_token)) if (self.current_token.tokentype == token.STRINGVAL or 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): simple_rvalue_node = ast.SimpleRValue() simple_rvalue_node.val = self.current_token self.__advance() # eat (we already know from 3-7 lines up) return simple_rvalue_node # return SimpleRValue node elif self.current_token.tokentype == token.NEW: self.__advance() # eat NEW (we already know from 1 line up) new_rvalue_node = ast.NewRValue() new_rvalue_node.struct_type = self.current_token self.__eat(token.ID, 'expected ID') return new_rvalue_node # return NewRValue node else: return self.__idrval() # return a different kind of RValue node
def __rvalue(self): """<rvalue> ::= STRINGVAL | INTVAL | BOOLVAL | FLOATVAL | NIL | NEW ID | <idrval> """ rvalues = [ token.STRINGVAL, token.INTVAL, token.BOOLVAL, token.FLOATVAL, token.NIL ] rval = None if self.current_token.tokentype in rvalues: rval = ast.SimpleRValue() rval.val = self.current_token self.__advance() elif self.__tokenIs(token.NEW): self.__advance() rval = ast.NewRValue() rval.struct_type = self.current_token self.__eat(token.ID, "expected an ID") else: rval = self.__idrval() return rval
def __rvalue(self): """<rvalue> ::= STRINGVAL | INTVAL | BOOLVAL | FLOATVAL | NIL | NEW ID | <idrval>""" types = [token.STRINGVAL, token.INTVAL, token.BOOLVAL] types.extend([token.FLOATVAL, token.NIL]) if self.current_token.tokentype == token.NEW: new_r_value_node = ast.NewRValue() self.__advance() new_r_value_node.struct_type = self.current_token self.__eat(token.ID, "expecting an identifier") return new_r_value_node elif self.current_token.tokentype == token.ID: return self.__idrval() elif self.current_token.tokentype in types: simple_rvalue_node = ast.SimpleRValue() simple_rvalue_node.val = self.current_token self.__advance() return simple_rvalue_node else: s = 'expected a rvalue found"' + self.current_token.lexeme + '" in parser' l = self.current_token.line c = self.current_token.column raise error.MyPLError(s, l, c)
def __idrval(self): """<idrval> ::= ID ( DOT ID )* | ID LPAREN <exprlist> RPAREN""" rStmt = ast.SimpleRValue() rStmt.val = self.current_token self.__eat(token.ID, "expecting ID") if self.current_token.tokentype == token.LPAREN: temp = rStmt.val rStmt = ast.CallRValue() rStmt.fun = temp self.__advance() self.__exprlist(rStmt) self.__eat(token.RPAREN, "expecting a ')'") return rStmt else: if self.current_token.tokentype == token.DOT: temp = rStmt.val rStmt = ast.IDRvalue() rStmt.path.append(temp) while self.current_token.tokentype == token.DOT: self.__advance() temp = self.current_token rStmt.path.append(temp) self.__eat(token.ID, "expecting an ID") return rStmt