给定 BNF 语法输出 C# 的解析器生成器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/153572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 15:52:01  来源:igfitidea点击:

Parser-generator that outputs C# given a BNF grammar?

提问by ilitirit

I'm looking for a tool that will be able to build a parser (in C#) if I give it a BNF grammar (eg. http://savage.net.au/SQL/sql-2003-2.bnf)

如果我给它一个 BNF 语法(例如http://savage.net.au/SQL/sql-2003-2.bnf),我正在寻找一种能够构建解析器(在 C# 中)的工具

Does such a generator exist?

这样的生成器存在吗?

采纳答案by leppie

Normally BNF grammars are too ambiguous. ANTLR will be probably good for what you are looking for.

通常 BNF 文法过于模糊。ANTLR 可能适合您正在寻找的内容。

回答by Jonathan C Dickinson

You will have to tweak the BNF a bit, but TinyPGis a great tool.

您将不得不稍微调整 BNF,但TinyPG是一个很棒的工具。

回答by Tormod Fjeldsk?r

The Visual Studio SDKactually ships with lexer and parser generation tools. These are called MPPG and MPLex and are part of the Managed Babelpackage. While the intention of bundling them with the SDK is to develop language extensions for Visual Studio, they are perfectly usable for creating general AST-emitting parsers.

Visual Studio的SDK实际上附带词法和语法分析器生成工具。它们被称为 MPPG 和 MPLex,是Managed Babel包的一部分。虽然将它们与 SDK 捆绑在一起的目的是为 Visual Studio 开发语言扩展,但它们非常适用于创建通用的 AST 发射解析器。

MPLex and MPPG are based on GPLEXand GPPG(projects of Queensland University of Technology) and are used in a similar fashion to Lex and Yacc. The SDK also contains MSBuild actions for making the parser generation a part of the regular build process.

MPLex 和 MPPG 基于GPLEXGPPG(昆士兰科技大学的项目),并以与 Lex 和 Yacc 类似的方式使用。SDK 还包含 MSBuild 操作,用于使解析器生成成为常规构建过程的一部分。

Here's a screencast showing MPLex and MPPG in action:
http://msdn.microsoft.com/en-us/vstudio/cc837016.aspx

这是显示 MPLex 和 MPPG 运行的截屏视频:http:
//msdn.microsoft.com/en-us/vstudio/cc837016.aspx

回答by Gian Marco Gherardi

Also take a look at Irony:

还可以看看 Irony:

http://irony.codeplex.com/

http://irony.codeplex.com/

seems very promising

看起来很有前途

回答by Kevin Kelley

IronMetais a C# implementation of Alex Warth's OMeta; it's a packrat PEG (parsing expression grammar; uses biased choice), so grammars can be cleaner than when using a yacc-like LALR system.

IronMeta是 Alex Warth 的OMeta的 C# 实现;它是一个 Packrat PEG(解析表达式语法;使用有偏见的选择),因此与使用类似 yacc 的 LALR 系统相比,语法可以更清晰。