parsing - 动态 (?) 解析器

标签 parsing compiler-construction interpreter lex

是否存在在运行时生成 AST/解析树的解析器?有点像一个库,它会接受一串 EBNF 语法或类似的东西并吐出数据结构?

  • 我知道 antlr、jlex 和他们的同类。他们生成可以做到这一点的源代码。 (喜欢跳过编译步骤)
  • 我知道 Boost::Spirit,它使用一些带有 C++ 语法的黑魔法在执行时生成这样的东西(绝对更接近我想要的东西,但是当谈到 C++ 时我是个笨蛋。它仍然有点限制,因为你的语法是硬编码的)
  • 我对 python 或 ruby​​ 一无所知,尽管编译器编译器在这种语言中可能很有效...

  • 现在我知道解析器组合器。 (谢谢,乔纳斯)还有一些图书馆(谢谢 eliben)
    顺便说一句,我也注意到Parsing Expression Grammars最近,有人实现它听起来很酷(他们说 Perl 6 会有它,但 Perl 回避了我的理解)

    最佳答案

    看看parser combinators我认为这可以帮助你。可以使用这种技术在运行时创建解析器。一种流行的解析器组合器是 Parsec使用 Haskell作为它的宿主语言。来自 parsec documentation :

    Combinator parsers are written and used within the same programming language as the rest of the program. There is no gap between the grammar formalism (Yacc) and the actual programming language used (C)

    Parsers are first-class values within the language. They can be put into lists, passed as parameters and returned as values. It is easy extend the available set of parsers with custom made parsers specific for a certain problem


    如果您使用 .NET,请查看 parser combinator library for F# .

    关于parsing - 动态 (?) 解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/185584/

    相关文章:

    compiler-construction - makefile - 如何处理 kconfig 文件

    python - 避免 python 设置时间

    c++ - 奇怪的编译错误 C++ "undefined reference"& "relocation truncated"

    R包和执行时间

    python - 来自 python 的 bash 的 pwd 展开符号链接(symbolic link)

    编译器和解释器之间的混淆?

    java - 将一个类的字段复制到另一个类的相同字段

    用于解析干净 URL 并获取其不同组件的 Java 库/类

    php - 应该如何用PHP(简单的html dom解析器)解析网页的背景图像和其他图像?

    objective-c - 解析 Objective C 错误中的 JSON 值?