All pastes #405781 Raw Edit

Stuff

public python v1 · immutable
·published 2007-03-21 22:42 UTC
rendered paste body
class sampleLex:	def __init__(self):		self.fileName = raw_input("Please enter file name: ")		self.f = open(self.fileName, 'r')		self.fLines = self.f.readlines()		self.alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m'					,'n','o','p','q','r','s','t','u','v','w','x','y','z']		self.digit = ['0','1','2','3','4','5','6','7','8','9']		self.table = [[1,3,0],					  [1,1,2],					  [2,2,2],					  [3,3,3]]		self.relations = {"alpha":0, "digit":1}		self.charStack = []		self.state = 0		self.scan()			def scan(self):		for x in range(0,len(self.fLines)):			for y in range(0,len(self.fLines[x])):				if self.state is 3:					print "Error"					self.state = 0					del self.charStack[:]									elif self.state is 2:					print ''.join(self.charStack)					self.state = 0					del self.charStack[:]									print self.state				self.state = self.table[self.state][self.lex(self.state, self.fLines[x][y])]					def lex(self, currState, currChar):		if currChar in self.alpha:			self.charStack.append(currChar)			return int(self.relations["alpha"])		elif currChar in self.digit:			self.charStack.append(currChar)			return int(self.relations["digit"])			sL = sampleLex()