为什么在线解析器似乎停止在正则表达式上? [英] Why do on-line parsers seem to stop at regexps?

查看:81
本文介绍了为什么在线解析器似乎停止在正则表达式上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道为什么似乎没有解析器,例如 BNF ,其行为类似于各种库中的正则表达式.

I've been wondering for long why there doesn't seem to be any parsers for, say, BNF, that behave like regexps in various libraries.

当然,有些东西是 ANTLR

Sure, there's things like ANTLR, Yacc and many others that generate code which, in turn, can parse a CFG, but there doesn't seem to be a library that can do that without the intermediate step.

我有兴趣编写 Packrat解析器,以引导所有嵌套的与正则表达式相关的-括号怪癖(对于运动而言,甚至可能更多),但不知何故,我有种感觉,就是我正步入另一个停顿的问题-沼泽类.

I'm interested in writing a Packrat parser, to boot all those nested-parenthesis-quirks associated with regexps (and, perhaps even more so, for the sport of it), but somehow I have this feeling that I'm just walking into another halting problem -like class of swamps.

这些解析器是否存在技术/理论上的限制?或者我只是缺少什么?

Is there a technical/theoretical limitation for these parsers, or am I just missing something?

推荐答案

我认为这更像是一种文化.上下文无关文法的使用主要限于编译器,编译器通常具有与每个生产规则关联的代码.在某些语言中,输出代码比模拟回调要容易.在其他文章中,您将看到解析器库:例如,Haskell中的解析器组合器.另一方面,正则表达式在grep之类的工具中得到了广泛的应用,在每次用户提供新的正则表达式时都很难运行C编译器.

I think it's more of a cultural thing. The use of context-free grammars is mostly confined to compilers, which typically have code associated with each production rule. In some languages, it's easier to output code than to simulate callbacks. In others, you'll see parser libraries: parser combinators in Haskell, for example. On the other hand, regular expressions see wide use in tools like grep, where it's inconvenient to run the C compiler every time the user gives a new regular expression.

这篇关于为什么在线解析器似乎停止在正则表达式上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆