import parser, symbol, sys, token
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:
            for i in range(0, len(node) - 1):
                queue.insert(i, node[i + 1])
    return pairs

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)