[Tutor] state machines

Kirk Bailey idiot1 at netzero.net
Sat Sep 13 02:23:17 EDT 2003


I am working on a wiki for windows, and this time I want to whack at state 
machines, and I am using a bit of recursion in it. Here is some code:

# wordscanner routine								# reset the linepointer we will use it again...
for line in page:				# see?
	wordcounter=0				#
	wordlist = string.split(line,' ')	# split the line
	for word in wordlist:
		if isin(word,'http://'):	# if is hyperlink:
			if isin(word,'"'):	# DO NOT process "http
				pass		# DO NOT process;
			else:			# otherwise,
				wordlist[wordcounter]='<a href="' + word + '">' + word + '</a>' # ware word 
wrap!!!
		else:	OK, it's not an external link, test 4 wikiword...
			if iswikiword(word):
				wordlist[wordcounter]=makewikiword(word)
			else:
				pass		# leave word alone
		wordcounter=wordcounter+1
	line=string.join(wordlist,' ')
	page[linecounter]=line
	linecounter=linecounter+1
#

ok, here are some relevant definitions:
def iswikiword(word):			# Tests to see if a word is a wikiword
	if word:
		if word[0] in string.ascii_letters:		# must be a letter!
			return result=isfirstuppercase(word[1:]) # first rule: letters only		else:
			return 0		# word with any nonletter in it is not wikiword.
	else:
		return 0			# second rule: no null words.
#
def isfirstlowercase:
	if word:
		if word[0] in string.ascii_lowercase:	# if it spins around here, it
			isfirstlowerercase(word[1:])		# is NOT a wikiword! return 0!
		else:
			isuppercase(word[1:])
	else:
		return 0
#
def isfirstuppercase(word):
	if word:				# a string of any size is a logical 1
		if word[0] in string.ascii_uppercase:
			return isfirstlowercase(word[1:])
		else:
			return 0
	else:
		return 0			
#
def isuppercase(word):
	if word:
		if word[0] in string.ascii.uppercase:
			return islowercase(word[1:])
		else:
			return 0
	else:
		return 0
#
def islowercase(word):
	if word:
		if word[0] in string.ascii_lowercase:
			return 1
	else:
		return 0
#

still working on it.
-- 

-- 

end

Cheers!
         Kirk D Bailey

  +                              think                                +
   http://www.howlermonkey.net  +-----+        http://www.tinylist.org
   http://www.listville.net     | BOX |  http://www.sacredelectron.org
   Thou art free"-ERIS          +-----+     'Got a light?'-Prometheus
  +                              kniht                                +

Fnord.




More information about the Tutor mailing list