Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- deftokens = tokens[:]
- rules.append("-")
- tokens = []
- curr = 0 # position in deftokens
- pos = 0
- stack = [] # numbers of rules
- tokens.append(deftokens[curr])
- #print(tokens)
- #print(library[4][0])
- #print(tokens)
- def funcoff(dd):
- global curr, tokens, stack, rules, library
- #print(tokens)
- while (len(tokens) > 1 or tokens[0] != "Programm") and len(rules) > 0:
- i = 0 # pos
- while i < len(library):
- q = len(tokens) - len(library[i][0])
- if len(tokens) >= len(library[i][0]) \
- and eqlist(tokens[q:], library[i][0]):
- if (library[i][1] != "Variable" or curr > 13):
- tokens = tokens[:q]
- tokens.append(library[i][1])
- stack.append(i)
- rules.append(library[i][1])
- if funcoff(dd + 1):
- return 1
- # if the rule was wrapped, we go to lower level
- # print(dd)
- # i = 0#
- # continue#
- # pos = 0#
- i = i + 1
- if curr + 1 < len(deftokens):
- curr = curr + 1
- tokens.append(deftokens[curr])
- rules.append("-")
- pos = 0
- else:
- while (len(rules) > 0 and rules[len(rules) - 1] == "-"):
- w = rules.pop()
- tokens.pop()
- curr = curr - 1
- if (len(rules) == 0):
- break
- w = rules.pop()
- # print("w=")
- # print(w)
- tokens.pop()
- pos = stack.pop() + 1
- # print(library[pos-1][0])
- tokens.extend(library[pos - 1][0])
- # print("before\n")
- # print(tokens)
- return 0
- return 1
- funcoff(0)
- if len(tokens) == 1:
- print("OK")
- print(rules)
- else:
- print("Wrong2")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement