All pastes #405848 Raw Edit

Untitled

public python v1 · immutable
·published 2007-03-21 23:52 UTC
rendered paste body
class sampleLex:	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']	digit = ['0','1','2','3','4','5','6','7','8','9']	table = [[1,3,0],			[1,1,2],			[2,2,2],			[3,3,3]]	relations = {"alpha":0, "digit":1}	charStack = []	state = 0	def __init__(self, fName):		self.f = open(fName, 'r')		self.fLines = self.f.readlines()		self.scan()			def scan(self):		for line in self.fLines:			for c in line:				if state is 3:					print "Error"					state = 0					charStack = []									elif self.state is 2:					print ''.join(charStack)					state = 0					charStack = []									print state				state = table[state][self.lex(line[c])]					def lex(self, currChar):		if currChar in alpha:			charStack.append(currChar)			return int(relations["alpha"])		elif currChar in digit:			charStack.append(currChar)			return int(relations["digit"])						fileName = raw_input("Please enter file name: ")sL = sampleLex(fileName)