Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def infinite(instructions, slowSymbols, fastSymbols):
- #instructions is a map of tuple instructions of the format
- #(x, y[])
- #x=non-terminal char
- #y = list of possible production results for the character y. IE:
- # the "A1" in A->A1.
- #when it is not an infinite lang.
- if len(fastSymbols) == 0:
- return False
- for symbol in slowSymbols:
- if symbol in fastSymbols:
- return True
- #deepen once for slow ticker
- newSlow = deepen(instructions, slowSymbols)
- #deepen twice for fast ticker
- newFast = deepen(instructions, fastSymbols)
- newFast = deepen(instructions, newFast)
- def deepen(instructions, arbSymbols):
- """takes a list of symbols and dives one layer deeper into the tree of
- possibilities for all symbols"""
- newArbSymbols = []
- for symbol in arbSymbols:
- #for each symbol, get the list of production strings associated
- newSymbolStrings = instructions[symbol]
- #iterate through each resulting production string
- for newString in newSymbolStrings:
- #examine the individual chars in that string of what it becomes
- newSymbols = list(newString)
- #goes char by char to check if there is an instruction for that symbol
- #if there is, add it into the new list of slow symbols.
- #adds all corresponding chars.
- for newSymbol in newSymbols:
- if newSymbol in instructions and newSymbol not in newSlow:
- newArbSymbols.append(newSymbol)
- #returns compiled list of 1 depth deeper.
- return newArbSymbols
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement