0

In this list I found symbols of Python grammar, which contains in parse tree of Python source.

For example if I use

parser.st2tuple(parser.suite(open(SRC_FILENAME).read()))

for some source file SRC_FILENAME, I get a parse tree with following format:

                                        (307,
                                         (308,
                                          (309,
                                           (312,
                                            (313,
                                             (314,
                                              (315,
                                               (316,
                                                (317,
                                                 (318,
                                                  (319,
                                                   (320,
                                                    (1,
                                                     'Type'))))))))))))))))),
                                    (8,
                                     ')'))))))))))))))))),
                    (8, ')')))))))))))))))))),
   (4, ''))),
 (4, ''),
 (0, ''))

But all Python grammar constants in list has numbers greater than 256. Withal, there are many numbers in my tree, which less than 256.

So where can I find the description of symbols, which has numbers less than 256?

Community
  • 1
  • 1
VeLKerr
  • 2,995
  • 3
  • 24
  • 47
  • 1
    Why don't you use `ast`? It's much more readable. – jonrsharpe Jun 27 '15 at 16:27
  • Maybe they are opcodes ? https://github.com/python/cpython/blob/master/Include/opcode.h – mitghi Jun 27 '15 at 16:28
  • @jonrsharpe , thanks. I tried to use `ast` as following: `ast.dump(ast.parse(open(SRC_FILENAME).read()))`. But I get not very readable output? Does the other way of using `ast` to get much readable tree exists? – VeLKerr Jun 27 '15 at 17:04
  • @VeLKerr, what are you trying to do? ast.dump can give you quite cluttered output especially for larger files – Padraic Cunningham Jun 27 '15 at 17:30
  • @Padraic Cunningham, I need to get parse tree from python source. Then I need to walk around this tree and fill the special table (which contains classes, functions, variables and other elements) – VeLKerr Jun 27 '15 at 17:44
  • 1
    @VeLKerr, do you mean you want to modify the source? You might find the second part of this answer useful http://stackoverflow.com/questions/31078439/modify-function-in-decorator/31081432#31081432 and http://stackoverflow.com/questions/30199328/how-can-i-find-python-methods-without-return-statements/30200033#30200033 and http://stackoverflow.com/questions/30037326/how-to-textually-find-an-imported-name-in-a-module/30037842#30037842 – Padraic Cunningham Jun 27 '15 at 17:45
  • @PadraicCunningham, no I don't want to modify the source. I only want to **analyze** it. – VeLKerr Jun 27 '15 at 17:48
  • 1
    Then ast.dump is probably good as you will get bar using nodeVisitor – Padraic Cunningham Jun 27 '15 at 17:53
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/81732/discussion-between-velkerr-and-padraic-cunningham). – VeLKerr Jun 27 '15 at 17:57

0 Answers0