在 Haskell 中编写 Perl 代码生成器涉及哪些步骤?
鉴于 Perl 5 不符合 BNF,我不知道如何思考这个问题。有人可以提供一些建议让我以正确的方式思考这个问题吗?
Given that Perl 5 does not conform to BNF, I'm at a loss as to how to think about this problem. Could someone offer some advice to set me off in the right way thinking about this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取决于您想要生成什么。
如果您希望生成的 Perl 代码确实符合 BNF,那么您显然(正确地)认为有一个解决方案:构建对应于 Perl 片段的树,然后漂亮地打印该树。只有当您坚持生成相同的语法时,这才会成为问题,而 Perl 可能会模糊地解释该语法。
您还可以简单地使用 Perl 代码的文本模板并填充插槽。如果您的代码生成器不必以复杂的方式组合各个部分,那么这也可以正常工作。
Depends on what you want to generate.
If the Perl code you wish to generate does conform to a BNF, then you clearly think (rightly) that there's a solution: build a tree corresponding to Perl fragment, and then prettyprint the tree. This will only be an issue if you insist on generating the same syntax, which can be ambiguously interpreted by Perl.
You can also simply use text templates for the Perl code and fill in the slots. If you code generator doesn't have to compose the pieces in complicated ways, this will work fine, too.