def matchStringSkippingWhitespace(self, string, errorOnFailure = None): e.bark(SettingsHeader.MEDIUM_BARK, 'entering matchStringSkippingWhitespace') e.bark(SettingsHeader.LOW_LEVEL, 'skipping whitespace') self.skipWhitespace() rtrn = self.matchString(string, errorOnFailure) #self.skipWhitespace() return rtrn
def useVar(self): name = self.recordStack.pop() if self.varExists(name): self.stackPush(self.retrieveObjects([name])[0].value) e.bark(HIGH_LEVEL, 'stack =', self.stack) #print self.stack else: return False
def matchStringSkippingWhitespace(self, string, errorOnFailure=None): e.bark(SettingsHeader.MEDIUM_BARK, 'entering matchStringSkippingWhitespace') e.bark(SettingsHeader.LOW_LEVEL, 'skipping whitespace') self.skipWhitespace() rtrn = self.matchString(string, errorOnFailure) #self.skipWhitespace() return rtrn
def stackPop(self): if self.stackLength() > 0: self.registerA = self.stack.pop() e.bark(HIGH_LEVEL, 'stack =', self.stack) return self.registerA else: memSizeError() e.bark(HIGH_LEVEL, 'stack =', self.stack)
def pushDigit(self): e.bark(MEDIUM_BARK, 'l', self.lastNonemptyStringMatched) if type(self.lastNonemptyStringMatched) == type('') and \ len(self.lastNonemptyStringMatched) == 1: digit = ord(self.lastNonemptyStringMatched) - ord('0') if True: #self.stackLength() >= 2: self.num = digit + 10 * self.num else: self.num = digit else: self.expressionError('not a digit!') return False
def matchChar(self, char, errorOnFailure): e.bark(SettingsHeader.LOW_LEVEL, 'trying to match', char) if self.current() == char: self.next() e.bark(SettingsHeader.LOW_LEVEL, 'matched', char, '', 'new pos =', self.position) return True else: if errorOnFailure: e.error(level = SettingsHeader.MEDIUM, message = 'could not match character \'' + char + \ '\' in string \'' + self.string + '\' at position ' + str(self.position) + '.') else: return False
def matchChar(self, char, errorOnFailure): e.bark(SettingsHeader.LOW_LEVEL, 'trying to match', char) if self.current() == char: self.next() e.bark(SettingsHeader.LOW_LEVEL, 'matched', char, '', 'new pos =', self.position) return True else: if errorOnFailure: e.error(level = SettingsHeader.MEDIUM, message = 'could not match character \'' + char + \ '\' in string \'' + self.string + '\' at position ' + str(self.position) + '.') else: return False
def findFreeMemory(self, numberOfSlotsNeeded = 1): returnPositions = [] locationInMemory = self.__firstFreeMemoryPosition__ - 1 ## ( we subtract 1 because even in the very beginning of the following loop, we add 1 to locationInMemory) for i in xrange(numberOfSlotsNeeded): ## stop try: locationInMemory += 1 while self.getMemory(locationInMemory) != None: locationInMemory += 1 returnPositions += [locationInMemory] except SAMMemException: e.error(MEDIUM, 'not enough free memory! (' + len(returnPositions) + ' slots available out of ' + numberOfSlotsNeeded + ')') e.bark(MEDIUM_BARK, 'returnPositions=', returnPositions) return returnPositions
def matchString(self, string, errorOnFailure = None): e.bark(SettingsHeader.STATE_OF_HIGH_LEVEL_FUNCTION, 'entering matchString') if errorOnFailure == None: errorOnFailure = True if self.isReal() else False rtrn = True for char in string: e.bark(SettingsHeader.LOW_LEVEL, 'regex-char we want to match is', char) rtrn = self.matchChar(char, errorOnFailure) and rtrn ## ORDER MATTERS! e.bark(SettingsHeader.STATE_OF_HIGH_LEVEL_FUNCTION, 'exiting matchString', 'rtrn=', rtrn) return rtrn
def matchString(self, string, errorOnFailure=None): e.bark(SettingsHeader.STATE_OF_HIGH_LEVEL_FUNCTION, 'entering matchString') if errorOnFailure == None: errorOnFailure = True if self.isReal() else False rtrn = True for char in string: e.bark(SettingsHeader.LOW_LEVEL, 'regex-char we want to match is', char) rtrn = self.matchChar(char, errorOnFailure) and rtrn ## ORDER MATTERS! e.bark(SettingsHeader.STATE_OF_HIGH_LEVEL_FUNCTION, 'exiting matchString', 'rtrn=', rtrn) return rtrn
def current(self): e.bark(SettingsHeader.LOW_LEVEL, \ 'in current poos =', self.position, \ ' content=', self.string[self.position] if not self.isAtEnd() else None) if not self.isAtEnd(): return self.string[self.position]
def skipWhitespace(self): e.bark(SettingsHeader.LOWEST_LEVEL, 'entering SkipWhitespace') while self.current() in SymbolsClass.Symbols.whitespace: self.next() e.bark(SettingsHeader.LOWEST_LEVEL, 'skipped the whitespace char \'' + self.current() + '\'')
def next(self): self.position += 1 e.bark(SettingsHeader.LOW_LEVEL, 'Next ', 'pos was ', self.position - 1, ' pos is ', self.position)
def current(self): e.bark(SettingsHeader.LOW_LEVEL, \ 'in current poos =', self.position, \ ' content=', self.string[self.position] if not self.isAtEnd() else None) if not self.isAtEnd(): return self.string[self.position]
def stackPush(self, value): self.stack.append(value) e.bark(HIGH_LEVEL, 'stack =', self.stack)
def next(self): self.position += 1 e.bark(SettingsHeader.LOW_LEVEL, 'Next ', 'pos was ', self.position-1, ' pos is ', self.position)
def skipWhitespace(self): e.bark(SettingsHeader.LOWEST_LEVEL, 'entering SkipWhitespace') while self.current() in SymbolsClass.Symbols.whitespace: self.next() e.bark(SettingsHeader.LOWEST_LEVEL, 'skipped the whitespace char \''+self.current()+'\'')