basic AST question #228
-
I'm used to Yacc and Boost Spirit, so I'm not sure how to create my own AST using the actions, given they return void. Seems I have to manage some parsing stacks manually (like the calculator example). I could generate a parse tree, then convert it to my own AST (already written), but that seems wasteful in terms of allocations. It seems I can also define a custom node, however my AST should ideally be separated from the pgtl parser. Any help appreciated! thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You don't have to build the AST yourself, we already offer support for that. See https://github.com/taocpp/PEGTL/blob/master/doc/Parse-Tree.md. I wouldn't worry too much about allocations (we have some optimizations in place). Instead, look at our filters and transformation options, which can transform the parse tree nodes into an AST. |
Beta Was this translation helpful? Give feedback.
-
Thanks @d-frey! |
Beta Was this translation helpful? Give feedback.
You don't have to build the AST yourself, we already offer support for that. See https://github.com/taocpp/PEGTL/blob/master/doc/Parse-Tree.md. I wouldn't worry too much about allocations (we have some optimizations in place). Instead, look at our filters and transformation options, which can transform the parse tree nodes into an AST.