def __params(self): """<params> ::= ID COLON <type> ( COMMA ID COLON <type> )* | e""" params = [] if self.__tokenIs(token.ID): params = [] new_param = ast.FunParam() new_param.param_name = self.current_token self.__advance() self.__eat(token.COLON, "expected ':'") new_param.param_type = self.current_token params.append(new_param) self.__type() while (self.__tokenIs(token.COMMA)): new_param = ast.FunParam() self.__advance() new_param.param_name = self.current_token self.__eat(token.ID, "expected ID") self.__eat(token.COLON, "expected ':'") new_param.param_type = self.current_token params.append(new_param) self.__type() else: pass return params
def __params(self): param_list = [] param_node = ast.FunParam() if self.current_token.tokentype == token.ID: param_node.param_name = self.current_token self.__advance() self.__eat(token.COLON, "expecting ':'") param_node.param_type = self.__type() param_list.append(param_node) while self.current_token.tokentype == token.COMMA: param_node = ast.FunParam() self.__advance() param_node.param_name = self.current_token self.__eat(token.ID, "expecting an ID") self.__eat(token.COLON, "expecting ':'") param_node.param_type = self.__type() param_list.append(param_node) return param_list
def __params(self, functionNode): if self.current_token.tokentype == token.ID: funParamNode = ast.FunParam() funParamNode.param_name = self.current_token self.__eat(token.ID, 'expecting id') self.__eat(token.COLON, 'expecting colon') funParamNode.param_type = self.current_token self.__type() functionNode.params.append(funParamNode) while self.current_token.tokentype == token.COMMA: self.__eat(token.COMMA, 'expecting ,') funParamNode = ast.FunParam() funParamNode.param_name = self.current_token self.__eat(token.ID, 'expecting id') self.__eat(token.COLON, 'expecting :') funParamNode.param_type = self.current_token self.__type() functionNode.params.append(funParamNode)
def __params(self): """<params> ::= ID COLON <type> (COMMA ID COLON <type>)* | e""" paramsList = [] if self.current_token.tokentype == token.ID: param_node = ast.FunParam() param_node.param_name = self.current_token self.__advance() self.__eat(token.COLON, 'expecting a ":"') param_node.param_type = self.__type() paramsList.append(param_node) while self.current_token.tokentype == token.COMMA: self.__advance() param_node = ast.FunParam() param_node.param_name = self.current_token self.__eat(token.ID, "expecting an identifyer") self.__eat(token.COLON, 'expecting a ":"') param_node.param_type = self.__type() paramsList.append(param_node) return paramsList
def __params(self, nodeFromHeaven): """<params> ::= ID COLON <type> ( COMMA ID COLON <type> )* | E""" paramStmt = ast.FunParam() #print("ptest") if self.current_token.tokentype == token.ID: paramStmt.param_name = self.current_token self.__eat(token.ID, "expecting an ID") self.__eat(token.COLON, "expecting a ':'") paramStmt.param_type = self.__type() nodeFromHeaven.params.append(paramStmt) #print(paramStmt.param_name.lexeme, " " , nodeFromHeaven.params[0].param_name.lexeme) while self.current_token.tokentype == token.COMMA: paramStmt = ast.FunParam() self.__advance() paramStmt.param_name = self.current_token self.__eat(token.ID, "expecting an ID") self.__eat(token.COLON, "expecting a ':'") paramStmt.param_type = self.__type() nodeFromHeaven.params.append(paramStmt)
def __params(self): """<params> ::= ID COLON <type> ( COMMA ID COLON <type> )* | e""" param_list = [] if (self.current_token.tokentype == token.ID): fun_params_node = ast.FunParam() fun_params_node.param_name = self.current_token self.__advance() self.__eat(token.COLON, 'expecting ":"') fun_params_node.param_type = self.__type() param_list.append(fun_params_node) while (self.current_token.tokentype == token.COMMA): self.__advance() fun_params_node = ast.FunParam() fun_params_node.param_name = self.current_token self.__eat(token.ID, 'expecting "ID"') self.__eat(token.COLON, 'expecting ":"') fun_params_node.param_type = self.__type() param_list.append(fun_params_node) return param_list
def __params(self): # print("params: " + str(self.current_token)) fun_param_list = [] if self.current_token.tokentype == token.ID: fun_param = ast.FunParam() fun_param.param_name = self.current_token self.__advance() # eat ID (we already know from 2 lines up) self.__eat(token.COLON, 'expected ":"') fun_param.param_type = self.__type() fun_param_list.append(fun_param) # add first FunParam node to list (if it exists) while self.current_token.tokentype == token.COMMA: self.__advance() # eat COMMA (we already know from 1 line up) fun_param = ast.FunParam() # need to reset fun_param or the objects in the list are connected fun_param.param_name = self.current_token self.__eat(token.ID, 'expected ID') self.__eat(token.COLON, 'expected ":"') fun_param.param_type = self.__type() fun_param_list.append(fun_param) # add following FunParam nodes to list return fun_param_list
def __params(self, fun_node): if self.current_token.tokentype == token.ID: fun_params_node = ast.FunParam() fun_params_node.param_name = self.current_token self.__advance() self.__eat(token.COLON, 'expecting colon') type = [ token.ID, token.INTTYPE, token.FLOATTYPE, token.BOOLTYPE, token.STRINGTYPE ] if self.current_token.tokentype in type: fun_params_node.param_type = self.current_token self.__advance() fun_node.params.append(fun_params_node) while self.current_token.tokentype == token.COMMA: fun_params_node = ast.FunParam() self.__advance() fun_params_node.param_name = self.current_token self.__eat(token.ID, 'expecting ID') self.__eat(token.COLON, 'expecting :') if self.current_token.tokentype in type: fun_params_node.param_type = self.current_token self.__advance() fun_node.params.append(fun_params_node)