Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. deftokens = tokens[:]
  2. rules.append("-")
  3. tokens = []
  4. curr = 0 # position in deftokens
  5. pos = 0
  6. stack = [] # numbers of rules
  7. tokens.append(deftokens[curr])
  8. #print(tokens)
  9.  
  10. #print(library[4][0])
  11. #print(tokens)
  12.  
  13.  
  14. def funcoff(dd):
  15. global curr, tokens, stack, rules, library
  16. #print(tokens)
  17. while (len(tokens) > 1 or tokens[0] != "Programm") and len(rules) > 0:
  18. i = 0 # pos
  19. while i < len(library):
  20. q = len(tokens) - len(library[i][0])
  21. if len(tokens) >= len(library[i][0]) \
  22. and eqlist(tokens[q:], library[i][0]):
  23. if (library[i][1] != "Variable" or curr > 13):
  24. tokens = tokens[:q]
  25. tokens.append(library[i][1])
  26. stack.append(i)
  27. rules.append(library[i][1])
  28.  
  29. if funcoff(dd + 1):
  30. return 1
  31. # if the rule was wrapped, we go to lower level
  32. # print(dd)
  33. # i = 0#
  34. # continue#
  35. # pos = 0#
  36. i = i + 1
  37. if curr + 1 < len(deftokens):
  38. curr = curr + 1
  39. tokens.append(deftokens[curr])
  40. rules.append("-")
  41. pos = 0
  42. else:
  43. while (len(rules) > 0 and rules[len(rules) - 1] == "-"):
  44. w = rules.pop()
  45. tokens.pop()
  46. curr = curr - 1
  47. if (len(rules) == 0):
  48. break
  49. w = rules.pop()
  50. # print("w=")
  51. # print(w)
  52. tokens.pop()
  53. pos = stack.pop() + 1
  54. # print(library[pos-1][0])
  55. tokens.extend(library[pos - 1][0])
  56. # print("before\n")
  57. # print(tokens)
  58. return 0
  59. return 1
  60.  
  61. funcoff(0)
  62. if len(tokens) == 1:
  63. print("OK")
  64. print(rules)
  65. else:
  66. print("Wrong2")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement