我应该使用 Workflow 还是 fsYacc?
我有一个非常简单的 DSL,需要在 .Net 平台上解析。我对解析器的经验不是很丰富,因此一直在查看使用 F#(fsLex、fsYacc、FParsec)的示例。我对 F# 不太熟悉,但对 Workflow 和 LINQ 有一些经验。
鉴于 DSL 的简单性,我可以不用使用 LINQ 来实现词法分析器。工作流(我将使用 V4)对于实现语法很有吸引力,因为我对它更熟悉,考虑到它的图形性质,更容易向其他人解释,而且它得到了 Microsoft 的支持,并且大概会继续发展。
然而,如果我的 DSL 变得更加复杂,我可以想象 WF 实现会变成一个嵌套的活动地狱,而基于 LINQ 的词法分析器也会以同样的方式发展。那时,学习 F# 并使用其中一种 F# 工具会更有意义。
我想知道其他人是否比较过 WF 和 F# 解析工具来实现简单的 DSL 解释器,以及结论可能是什么。
I have a very simple DSL I need to parse on a .Net platform. Not being very experienced with parsers, I have been looking at examples using F# (fsLex, fsYacc, FParsec). I am not that familiar with F#, but do have some experience with Workflow and LINQ.
Given the simplicity of the DSL, I can get away with using LINQ to implement the lexer. Workflow (I would be using V4) is appealing to implement the grammar, since I am more familiar with it, it's easier to explain to others given its graphic nature, and it is supported by Microsoft and will continue to evolve, presumably.
If my DSL becomes more sophisticated, however, I can image the WF implementation becoming a nested hell of activities and a LINQ based lexer going the same way. At that point learning F# and using one of the F# tools would make more sense.
I am wondering if others have compared WF and F# parsing tools to implement a simple DSL interpreter and what the conclusions might be.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不进一步了解 DSL 的用途以及它未来可能变得多么复杂,就很难给出答案。如果您的 DSL 与工作流程有关,那么 WF 似乎是存储解析结果的非常合理的选择。
如果您的语言不太复杂,那么 LINQ 或手动小型解析器就可以很好地完成。保持简单并使用同事知道的工具是件好事。
然而,当你的语言变得更加复杂时,这种方法往往很快就会崩溃。但从好的方面来说,你可以切换你的解析器。不要解决你可能永远不会遇到的问题。
就我个人而言,我非常喜欢 FParsec 进行解析。它需要一些关于 F# 的知识,但当你了解它时,它对于将文本转换为 AST 非常强大,而且它非常精简,因为没有“神奇的步骤”将你的 EBNF 转换为乱码,你可以看看它是如何工作的并对其进行调整。
当您没有时间深入研究 F# 和 FParsec 时,还有 Irony,它类似于 FParsec,但适用于 C# 。
这就是我从您告诉我们的情况中可以说的,如果您有任何具体问题,请告诉我们。
平均GJ
It's hard to give an answer without knowing a little more about what the DSL is supposed to do and how complex it may get in the future. If your DSL is about workflow then WF would seem like a very logical choice to store your parsed results in.
If your language is not too complex then LINQ or a handrolled little parser could very well do. It's good to keep it simple and use tooling that your colleagues know.
When your language becomes more complicated however this approach tends to come apart pretty quickly. But on the upside, you can just switch your parser then. Don't solve problems you may never have.
Personally I really like FParsec for parsing. It requires some knowledge about F# but when you've got your head around it it is so insanely powerful for turning text into AST, and it's very lean in that there are no 'magical steps' that turns your EBNF into gibberish code, you can see how it works and tune it.
When you don't have time to dive into F# and FParsec there's also Irony which is like FParsec but then for C#.
This is what I can say from what you've told us, if you have any concrete issues let us know.
Rgds GJ