]> git.saurik.com Git - cycript.git/blame - jammed.py
Remove "!super" hack: "super" is always a keyword.
[cycript.git] / jammed.py
CommitLineData
63db22e5
JF
1#!/usr/bin/python
2
3import re
4import sys
5
6tables = dict()
7defines = dict()
8
9with open(sys.argv[1], 'r') as file:
10 while True:
11 line = file.readline()
12 if line == '':
13 break
14
15 define = re.match('#define ([A-Za-z_]*) ([0-9]+)', line)
16 if define != None:
17 defines[define.group(1)] = int(define.group(2))
18 continue
19
20 if not line.startswith('static yyconst '):
21 continue
22
23 end = line.index('[')
24 begin = line.rindex(' ', 0, end)
25 name = line[begin+1:end]
26
27 code = ''
28 while True:
29 line = file.readline()
30 code += line
31 if line.find(';') != -1:
32 break
33
34 code = code.replace('{', '[')
35 code = code.replace('}', ']')
36 code = code.replace(';', ' ')
37 tables[name] = eval(code)
38
39yy_nxt = tables['yy_nxt']
40yy_accept = tables['yy_accept']
41yy_ec = tables['yy_ec']
42
43YY_NUM_RULES = defines['YY_NUM_RULES']
44try:
45 jammed = yy_accept.index(YY_NUM_RULES)
46except ValueError:
47 sys.exit(0)
48
49equivs = dict()
50for ordinal, equiv in enumerate(yy_ec):
51 equivs[equiv] = equivs.get(equiv, '') + chr(ordinal)
52
53starts = set(range(1, len(yy_nxt)))
54for source, table in enumerate(yy_nxt):
55 if source == 0:
56 continue
57 for equiv, target in enumerate(table):
58 if target in starts:
59 starts.remove(target)
60
61after = dict()
62after[jammed] = [[]]
63
64while True:
65 finish = dict()
66 for start in starts:
67 suffix = after.get(start)
68 if suffix == None:
69 continue
70 finish[start] = [[equivs[c] for c in s] for s in suffix]
71 if len(finish) != 0:
72 print finish
73 break
74
75 before = after
76 after = dict()
77
78 for source, table in enumerate(yy_nxt):
79 if source == 0:
80 continue
81 string = []
82 for equiv, target in enumerate(table):
83 suffix = before.get(target)
84 if suffix == None:
85 continue
86 string.extend([[equiv] + s for s in suffix])
87 if len(string) == 0:
88 continue
89 after[source] = string
90
91sys.exit(1)