All pastes #407125 Raw Edit

Someone

public python v1 · immutable
#407125 ·published 2007-03-22 22:05 UTC
rendered paste body
class SampleLex:	alpha = 'abcdefghijklmnopqrstuvwxyz'	digit = '0123456789'	table = [			[1,3,0],			[1,1,2],			[2,2,2],			[3,3,3],			]	relations = {		"alpha":0, 		"digit":1,	}	def __init__(self, file_name='ziew'):		self.f = open(file_name, 'r')		self.chars = []		self.state = 0			def scan(self):		for line in self.f.readlines():			for c in line:				if self.state == 3:					print "Error"					self.state = 0					self.chars = []								elif self.state == 2:					print ''.join(self.chars)					self.state = 0					self.chars = []					print self.state				else: 					self.state = self.table[self.state][self.lex(c)]					def lex(self, c):		self.chars.append(c)		if c in self.alpha:			return 1		elif c in self.digit:			return 2		else:			return 0file_name = raw_input("Please enter file name: ")lexer = SampleLex(file_name)lexer.scan()