All pastes #405843 Raw Edit

Unnamed

public python v1 · immutable
·published 2007-03-21 23:47 UTC
rendered paste body
class sampleLex:	def __init__(self, fName):		self.f = open(fName, '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 line in self.fLines:			for c in line:				if self.state is 3:					print "Error"					self.state = 0					self.charStack = []									elif self.state is 2:					print ''.join(self.charStack)					self.state = 0					self.charStack = []									print self.state				self.state = self.table[self.state][self.lex(self.state, line[c])]					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"])						fileName = raw_input("Please enter file name: ")sL = sampleLex(fileName)