2009-11-11 23:45:03 -05:00
|
|
|
import parser
|
|
|
|
import sys
|
|
|
|
import token
|
2007-07-05 16:18:09 -04:00
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
def proc(asttup):
|
|
|
|
queue = [asttup]
|
|
|
|
pairs = []
|
|
|
|
while queue:
|
|
|
|
node = queue.pop(0)
|
|
|
|
if not node:
|
|
|
|
continue
|
|
|
|
elif node[0] in token.tok_name:
|
|
|
|
pairs.append((token.tok_name[node[0]], node[1]))
|
|
|
|
else:
|
2009-11-12 00:01:05 -05:00
|
|
|
for i in xrange(0, len(node) - 1):
|
2007-07-05 16:18:09 -04:00
|
|
|
queue.insert(i, node[i + 1])
|
|
|
|
return pairs
|
|
|
|
|
2009-11-11 23:45:03 -05:00
|
|
|
if __name__ == "__main__":
|
|
|
|
for name in sys.argv[1:]:
|
|
|
|
f = open(name, 'r')
|
|
|
|
code = f.read()
|
|
|
|
f.close()
|
|
|
|
ast = parser.suite(code)
|
|
|
|
pairs = proc(ast.totuple())
|
|
|
|
pprint(pairs)
|