简体   繁体   English

boost :: spirit :: x3 AST生成器?

[英]generator from boost::spirit::x3 AST?

Esteemed Colleagues, 尊敬的同事,

I've a boost::spirit::x3 parser (of an AST) that works fine for its purpose of bringing in input files into our application. 我有一个boost :: spirit :: x3解析器(属于AST),可以将输入文件引入我们的应用程序,因此效果很好。

I'd like to flip things around and ask it to GENERATE output streams based on the same tree. 我想翻转一下内容,并要求它根据同一棵树生成输出流。

This is something I've never done. 这是我从未做过的事情。 Should I use boost::karma, or just write a visitor/walker for the tree? 我应该使用boost :: karma还是只为树写访客/步行者? What facilities does boost provide that might help me get started with either of these approaches? boost提供了哪些设施来帮助我开始使用这两种方法?

I imagine that specifying the recursion depth globally, and at each level might be useful as otherwise the output could be HUGE. 我想这是全局地指定递归深度,并且在每个级别上都可能有用,因为否则输出可能会很大。

Other issues for someone new to this to consider? 其他新手要考虑的问题?

Thanks! 谢谢!

There is nothing like Karma for X3. 没有像X3那样的Karma。

There are no facilities outside the underlying Proto library to traverse the expression tree. 基础Proto库之外没有任何设施可以遍历表达式树。

However. 然而。 You will run into predictable issues where the mapping from input-output is not a bijection. 您将遇到可预见的问题,其中从输入到输出的映射不是双射。 You will always have to pick a preferred output representation for such data, which means that your data may not roundtrip, you might have a lossy transform. 您将始终必须为此类数据选择首选的输出表示形式,这意味着您的数据可能不会往返,您可能会进行有损转换。 You need to take these into account. 您需要考虑这些。

I would actually not consider this. 我实际上不会考虑这一点。 Instead of tightly coupling my implementation on implementation details of a complicated library¹, I would base my algorithm on the AST or datastructures that you actually control. 我不会将我的实现与复杂库的实现细节紧密结合在一起¹,而是将算法基于您实际控制的AST或数据结构。


¹ like X3, which is also experimental, so things might change without notice ¹像X3一样,它也是实验性的,因此情况可能会发生变化,恕不另行通知

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM