F# 的 BNF 或 EBNF 解析器生成器中的 C# 语法
我正在寻找 C# v4 的 BNF 语法,我可以将其提供给 fsyacc,或者如果我找不到可以输出 F# 的基于 EBNF 的解析器生成器。
编辑: 我不想为 C# 编写一个解析器,而是为非常相似的语法编写一个实验性解析器,并且由于这两个语法之间存在巨大的文字重叠,我发现从 C# 语法开始并简单地更改偏离的位更容易。然而,我发现的 C#v4 的唯一语法是 EBNF,
替代答案是从 EBNF 到 BNF 的转换器
I'm looking for BNF grammar for C# v4 that I can feed to fsyacc or if I can't find that an EBNF based parser generator that can output F#.
EDIT:
I'm not looking to write a parser for C# but an experimental parser for a very similar grammar and since there's a huge literal overlap between the two grammars I find it easier to start with the C# grammar and simply change the bits that deviates. However the only grammar for C#v4 I've found is a EBNF
an alternative answer would be a converter from EBNF to BNF
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
扩展我之前的评论 - 我认为 C# 没有任何可以直接使用的可靠语法。有一些示例,但它们可能不会涵盖所有新功能(如 LINQ)或者不会经过很好的测试。
我能想到的最佳选择是使用 Mono 中 C# 编译器的解析器。这是用 C# 编写的,开源的,包括所有最新功能(而且也相当可靠)。有关详细信息,请参阅 Mono C# 编译器。您应该能够编译它并在 F# 中使用它(或修改它以使其对 F# 更加友好)。
Extending my previous comment - I don't think there's any solid grammar for C# that could be directly usable. There are some examples, but they probably won't cover all new features (like LINQ) or won't be very well tested.
The best option that I can think of is to use the parser from the C# compiler in Mono. This is written in C#, open-source, includes all recent features (and is also fairly solid). For more information, see Mono C# compiler. You should be able to compile that and use that from F# (or modify it to be more F# friendly).
根据 维基百科,Coco/R 是一个基于 EBNF 的解析器生成器。根据他们的 主页,有一个 F# 端口Coco/R(不过,最后更新时间为 2007 年 7 月 23 日,所以我预计会有一些重大更改)。如果你最终检查一下,我会对你的经历感兴趣。
我确实找到了 C# v2 的 BNF 语法: http://www.devincook.com/GOLDParser /grammars/index.htm
According to Wikipedia, Coco/R is an EBNF based parser generator. And according to their homepage, there is an F# port of Coco/R (last updated 2007-07-23, though, so I'd expect some breaking changes). If you end up checking it out, I'd be interested in your experience.
I did find a BNF grammer for C# v2: http://www.devincook.com/GOLDParser/grammars/index.htm
我在这里找到了一些语法;它们似乎包含最高 C# 4.0。
I found some grammars here; they seem to include up to C# 4.0.