views:

43

answers:

2

I'm using pyPEG to create a parse tree for a simple grammar. The tree is represented using lists and tuples. Here's an example:

[('command',
  [('directives',
    [('directive',
      [('name', 'retrieve')]),
     ('directive',
      [('name', 'commit')])]),
   ('filename',
    [('name', 'f30502')])])]

My question is what do I do with it at this point? I know a lot depends on what I am trying to do, but I haven't been able to find much about consuming/using parse trees, only creating them. Does anyone have any pointers to references I might use?

Thanks for your help.

+1  A: 

CSTs (concrete syntax trees) are quite hard to work with for some reasons. Therefore they're commonly converted to ASTs (abstract syntax tree) for further processing (details in the same article). For instance, the Python compiler (the component that turns Python source code into Python VM bytecode) translates CSTs to ASTs as part of its work.

Now, it really does strongly depend on your final goal. What are you parsing? What do you want to do with it? If you're re-creating a classical compilation flow, converting to an AST is probably a good way to proceed. Otherwise, you may find the CST enough - it all depends on what you need.

Eli Bendersky
A: 

Hi,

we have a community board for support for such questions around pyPEG. You can find it here: https://community.fdik.org/board/show/2/pypeg/

Yours, VB.

Volker Birk