def parse(self): self.id = Id() self.id.parse(TokList.getIdOrConst()) TokList.nextToken() TokList.match('ASSIGN', 'assign') self.expr = Expr() self.expr.parse() TokList.match('SEMICOLON', 'assign')
def parse(self): self.id = Id() #Passing in name of id to the parse function self.id.parse(TokList.getIdOrConst()) TokList.nextToken() if TokList.checkTok('COMMA'): TokList.match('COMMA', 'id list') self.id_list = IdList() self.id_list.parse()
def parseSpec(self, spec): spec = spec.split(' ')[2:] self.__parent = Id(spec.pop(0)) while spec: item = spec.pop(0) if item == 'classid' or item == 'flowid': self.__target = Id(spec.pop(0)) else: self.__params.append(item)
def parseSpec(self, spec): spec = spec.split(' ') self.__nodeType = spec.pop(0) self.__type = spec.pop(0) self.__id = Id(spec.pop(0)) if spec.pop(0) == 'parent': self.__parent = Id(spec.pop(0)) else: self.__parent = Id() if self.__nodeType == 'class' else None self.__params = self.__filterParams(spec)
def parseSpec(self, spec): spec = spec.split(' ') self._nodeType = spec.pop(0) self._type = spec.pop(0) self._id = Id(spec.pop(0)) if spec.pop(0) == 'parent': self._parent = Id(spec.pop(0)) else: self._parent = Id("{}:".format( self._id._major)) if self._nodeType == 'class' else None self._params = self._filterParams(spec)
def parse(self): if TokList.checkTok('CONST'): self.const = Const() self.const.parse(TokList.getIdOrConst()) TokList.nextToken() elif TokList.checkTok('ID'): self.id = Id() self.id.parse(TokList.getIdOrConst()) TokList.nextToken() elif TokList.match('LEFTPARAN', 'factor'): self.expr = Expr.Expr() self.expr.parse() TokList.match('RIGHTPARAN', 'factor')
def __init__(self, **d): """ """ self.iphi = d["iphi"] self.ieta = d["ieta"] self.depth = d["depth"] self.subdetName = d["subdetName"] self.subdet = SUBDET_NAME.index(self.subdetName) # set the id as the hash and declare the representation Id.__init__(self, self.myhash()) self.repr = "<DetId id=%d subdet=%s iphi=%d ieta=%d depth=%d>" % ( self.id, self.subdetName, self.iphi, self.ieta, self.depth)
def parse(self): TokList.match('CASE','case') self.id = Id() self.id.parse(TokList.getIdOrConst()) TokList.nextToken() TokList.match('OF','case') self.case_line = CaseLine() self.case_line.parse() TokList.match('ELSE','case') self.expr = Expr() self.expr.parse() TokList.match('END','case') TokList.match('SEMICOLON','case')
def getAttrs(self, accountNb=''): ''' returns all predefined attributes for the new member ''' attrs = {} if accountNb: # # if accountNb is given, a new family member is requested # # copy the attributes to be inherited from the main record of the family mainRecord = self.search('%s0' % accountNb[:-1]) iAttrs = mainRecord[0].allAttrs() for x in self.inheritAttributesFrom0: attrs[x] = iAttrs[x] # calculate next accountNb for the new family member familyRecords = self.search('%s_' % accountNb[:-1]) nbOfFamilyMember = familyRecords.count() attrs['accountNb'] = accountNb[:-1] + str(nbOfFamilyMember) else: # # new main member # # get next free member id memberId = Id.search('Member')[0] memberId.lastId = memberId.lastId + 10 attrs['accountNb'] = str(memberId.lastId) return attrs
def __init__(self, symbol, purchasePrice, currentPrice, quantity, purchaseDate): self.symbol = symbol self.purchasePrice = purchasePrice self.currentPrice = currentPrice self.quantity = quantity self.purchaseDate = purchaseDate self.purchaseId = Id().id
def __init__(self, **d): """ """ self.type = d["type"] self.crate = d["crate"] self.fiber = d["fiber"] self.fiberCh = d["fiberCh"] if self.type=="uTCA": self.slot = d["slot"] else: self.dcc = d["dcc"] self.spigot = d["spigot"] self.tb = d["tb"] # Id.__init__(self, self.myhash()) if self.type=="uTCA": self.repr = "<uTCA ElectronicsId id=%d crate=%d slot=%d fiber=%d fiberCh=%d>" % (self.id, self.crate, self.slot, self.fiber, self.fiberCh) else: self.repr = "<VME ElectronicsId id=%d crate=%d tb=%s dcc=%d spigot=%d fiber=%d fiberCh=%d>" % (self.id, self.crate, self.tb, self.dcc, self.spigot, self.fiber, self.fiberCh)
class Assign: def __init__(self): self.id = None self.expr = None #Simple parsing for Assign def parse(self): self.id = Id() self.id.parse(TokList.getIdOrConst()) TokList.nextToken() TokList.match('ASSIGN', 'assign') self.expr = Expr() self.expr.parse() TokList.match('SEMICOLON', 'assign') #Simple printing for Assign def print(self): TokList.printIndent() self.id.print() print(':=', end='') self.expr.print() print(';') #Executor that determines value of an expression and then sets that value to the respective Id def exec(self): val = self.expr.exec() self.id.setValue(val)
class Factor: def __init__(self): self.const = None self.id = None self.expr = None #Simple parsing that checks for constant, Id, or paranthesis def parse(self): if TokList.checkTok('CONST'): self.const = Const() self.const.parse(TokList.getIdOrConst()) TokList.nextToken() elif TokList.checkTok('ID'): self.id = Id() self.id.parse(TokList.getIdOrConst()) TokList.nextToken() elif TokList.match('LEFTPARAN', 'factor'): self.expr = Expr.Expr() self.expr.parse() TokList.match('RIGHTPARAN', 'factor') #Simple print statement def print(self): if self.const is not None: self.const.print() elif self.id is not None: self.id.print() elif self.expr is not None: print('(', end='') self.expr.print() print(')', end='') #Simple execution statement that returns a value based on parsing def exec(self): if self.const is not None: return self.const.exec() elif self.id is not None: return self.id.exec() elif self.expr is not None: return self.expr.exec()
def __init__(self, **d): """ """ self.type = d["type"] self.crate = d["crate"] self.fiber = d["fiber"] self.fiberCh = d["fiberCh"] if self.type == "uTCA": self.slot = d["slot"] else: self.dcc = d["dcc"] self.spigot = d["spigot"] self.tb = d["tb"] # Id.__init__(self, self.myhash()) if self.type == "uTCA": self.repr = "<uTCA ElectronicsId id=%d crate=%d slot=%d fiber=%d fiberCh=%d>" % ( self.id, self.crate, self.slot, self.fiber, self.fiberCh) else: self.repr = "<VME ElectronicsId id=%d crate=%d tb=%s dcc=%d spigot=%d fiber=%d fiberCh=%d>" % ( self.id, self.crate, self.tb, self.dcc, self.spigot, self.fiber, self.fiberCh)
class IdList: def __init__(self): self.id = None self.id_list = None #Simple parsing to check for further ids def parse(self): self.id = Id() #Passing in name of id to the parse function self.id.parse(TokList.getIdOrConst()) TokList.nextToken() if TokList.checkTok('COMMA'): TokList.match('COMMA', 'id list') self.id_list = IdList() self.id_list.parse() #Simple printing def print(self): self.id.print() if (self.id_list is not None): print(',', end='') self.id_list.print() def exec(self): pass #Used to set the values of all variables in an Id List, init determines whether it is initialization or not def setIdValues(self, init): if init == 1: if TokList.getIdValue(self.id.name) == 'null': print('ERROR: value ' + self.id.name + ' is already initialized') exit() #Initialized to 'null' as None is the previous assignment, 'null' is used later to check for initialization TokList.setIdValue(self.id.name, 'null') if self.id_list is not None: self.id_list.setIdValues(1) else: self.id.setValue(TokList.currentData()) TokList.nextData() if self.id_list is not None: self.id_list.setIdValues(0)
class Case: def __init__(self): self.case_line = None self.expr = None self.id = None #Simple parse of the case statement def parse(self): TokList.match('CASE','case') self.id = Id() self.id.parse(TokList.getIdOrConst()) TokList.nextToken() TokList.match('OF','case') self.case_line = CaseLine() self.case_line.parse() TokList.match('ELSE','case') self.expr = Expr() self.expr.parse() TokList.match('END','case') TokList.match('SEMICOLON','case') #Printing with proper indentation manipulation and new line printings def print(self): TokList.printIndent() print('case ', end='') self.id.print() print(' of') TokList.increaseIndent() TokList.printIndent() self.case_line.print() #Necessary for new line printings print() TokList.printIndent() print('else ', end='') self.expr.print() print() TokList.decreaseIndent() TokList.printIndent() print('end;') #Recursive execution based on values in the case line. Id value is passed in to all versions of case def exec(self): if not (self.case_line.exec(self.id)): self.id.setValue(self.expr.exec())
def get_id(self): IdToken = self.lex.get_next_token() Parser.match(IdToken, TokenType.ID_TOK) return Id(IdToken.get_lexeme()[0])
def __init__(self, investor, stocks=[], bonds=[]): self.investor = investor self.stocks = stocks self.bonds = bonds self.portfolioId = Id().id
def get_id(self): tok = self.get_next_token() self.match(tok, TokenType.ID_TOK) return Id.__new__(tok.Token.get_lexeme()[0])
def get_id(self): tok = self.lex.get_next_token() self.match(tok, TokenType.ID_TOK) return Id(tok.get_lexeme()[0])
def __init__(self, investor, stocks=[], bonds=[]): self.investor = investor self.portfolioId = Id().id self.createStockTable() self.createBondTable()
def getId(self): tok = self.getNextToken() if tok.getTokType() != TokenType.ID_TOK: raise Exception( "identifier expected at row " + tok.getRowNumber() + " and column " + tok.getColumnNumber()); return Id(tok.getLexeme()[0])
def __init__(self, first_name, last_name, address, phoneNumber): self.first_name = first_name self.last_name = last_name self.address = address self.phoneNumber = phoneNumber self.investorId = Id().id
def getId(self): tok = self.lex.getNextToken() self.match(tok, "ID_TOK") return Id(tok.getLexeme())