人们用像antlr javacc这样的解析器做什么?

发布于 2024-07-26 16:06:12 字数 96 浏览 6 评论 0原文

出于好奇,我想知道人们可以用解析器做什么,它们是如何应用的,以及人们通常用它创建什么?

我知道它在编程语言行业中广泛使用,但我认为这只是其中的一小部分,对吗?

Out of curiosity, I wonder what can people do with parsers, how they are applied, and what do people usually create with it?

I know it's widely used in programming language industry, however I think this is just a tiny portion of it, right?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

星軌x 2024-08-02 16:06:12

除了特殊用途的语言之外,我对解析器生成器最雄心勃勃的用途(在 C 中使用了很好的旧 yacc,后来又在 Python 中使用了 pyparsing)是从 SQL 查询中提取、验证并可能更改某些元信息 - 解析正确的 SQL 是一个真正的挑战(特别是如果您希望支持多种方言!-),解析器生成器(及其之上的词法分析器)至少删除了工作的那一部分!-)

Besides special-purpose languages, my most ambitious use of a parser generator yet (with good old yacc back in C, and again later with pyparsing in Python) was to extract, validate and possibly alter certain meta-info from SQL queries -- parsing SQL properly is a real challenge (especially if you hope to support more than one dialect!-), a parser generator (and a lexer it sits on top of) at least remove THAT part of the job!-)

假装爱人 2024-08-02 16:06:12

它们用于解析文本......

举一个更具体的例子,在我工作的地方,我们使用 lexx/yacc 来解析来自套接字的字符串。

另外,从名称中它应该可以让您了解 javacc 的用途(java 编译器编译器!)

They are used to parse text....

To give a more concrete example, where I work we use lexx/yacc to parse strings coming over sockets.

Also from the name it should give you an idea what javacc is used for (java compiler compiler!)

谁许谁一生繁华 2024-08-02 16:06:12

通常用于解析域特定语言或脚本语言,或对代码片段的类似支持。

Generally to parse Domain Specific Languages or scripting languages, or similar support for code snipits.

寄居人 2024-08-02 16:06:12

以前我见过它用于解析另一个软件工具的基于命令行的输出。 这样外部工具(VPN 软件)就可以重新使用基础路由器的 IPSec 代码而无需修改。 由于许多被解析的内容是 IP 路由表和其他结构化重复文本。

使用解析器允许在格式更改时进行简单的更改,而不是尝试查找和调整手写解析器。 而且输出确实改变了产品寿命的几次。

Previously I have seen it used to parse the command line based output of another software tool. This way the outer tool (VPN software) could re-use the base router IPSec code without modification. As lots of what was being parsed was IP Route tables and other structured repeated text.

Using a parser allowed simple changes when the formatting changed, instead of trying to find and tweak the a hand written parser. And the output did change a few times of the life of the product.

酒与心事 2024-08-02 16:06:12

我使用解析器帮助将 +/- 800 Clipper 源文件处理为类似的 PRG,这些 PRG 可以使用 Alaksa Xbase 32 进行编译。

I used parsers to help process +/- 800 Clipper source files into similar PRGs that could be compiled with Alaksa Xbase 32.

掩耳倾听 2024-08-02 16:06:12

您可以使用它来扩展您最喜欢的语言,方法是从其存储库获取其语言定义,然后添加您一直想要的内容。 您可以将常规语法传递给您的应用程序并在您自己的程序中处理扩展。

You can use it to extend your favorite language by getting its language definition from their repository and then adding what you've always wanted to have. You can pass the regular syntax to your application and handle the extension in your own program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文