Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. def infinite(instructions, slowSymbols, fastSymbols):
  2.     #instructions is a map of tuple instructions of the format
  3.     #(x, y[])
  4.     #x=non-terminal char
  5.     #y = list of possible production results for the character y. IE:
  6.         # the "A1" in A->A1.
  7.  
  8.     #when it is not an infinite lang.
  9.     if len(fastSymbols) == 0:
  10.         return False
  11.        
  12.     for symbol in slowSymbols:
  13.         if symbol in fastSymbols:
  14.             return True
  15.  
  16.     #deepen once for slow ticker
  17.     newSlow = deepen(instructions, slowSymbols)
  18.    
  19.     #deepen twice for fast ticker
  20.     newFast = deepen(instructions, fastSymbols)
  21.     newFast = deepen(instructions, newFast)
  22.  
  23. def deepen(instructions, arbSymbols):
  24.     """takes a list of symbols and dives one layer deeper into the tree of
  25.    possibilities for all symbols"""
  26.     newArbSymbols = []
  27.     for symbol in arbSymbols:
  28.         #for each symbol, get the list of production strings associated
  29.         newSymbolStrings = instructions[symbol]
  30.         #iterate through each resulting production string
  31.         for newString in newSymbolStrings:
  32.             #examine the individual chars in that string of what it becomes
  33.             newSymbols = list(newString)
  34.             #goes char by char to check if there is an instruction for that symbol
  35.             #if there is, add it into the new list of slow symbols.
  36.             #adds all corresponding chars.
  37.             for newSymbol in newSymbols:
  38.                 if newSymbol in instructions and newSymbol not in newSlow:
  39.                     newArbSymbols.append(newSymbol)
  40.                    
  41.     #returns compiled list of 1 depth deeper.
  42.     return newArbSymbols
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement