哪个解析器生成器对于操作产生式本身很有用?
类似于从上下文无关语法生成n个语句,我想从语法中随机生成句子。
什么是一个好的解析器生成器来操作实际语法产生式本身?我希望解析器生成器能够真正让我访问产品(产品对象?)。
如果我有一个类似于以下内容的语法:
start_symbol ::= foo
foo ::= bar | baz
什么是一个好的解析器生成器:
- 给我起始产生式符号,
- 允许我从起始符号的 RHS 中选择一个产生式(在本例中为
foo
), - 给我
foo
的产生式选项
显然,每个解析器都有产生式的内部表示以及将产生式与其 RHS 相关联的方法,但是哪个解析器可以轻松操纵这些内部结构呢?
注:博客条目 链接到我提到的另一个 SO 问题有某种自定义 CFG 解析器。我想为真正的解析器使用实际语法,而不是生成我自己的语法解析器。
Similar to Generating n statements from context-free grammars, I want to randomly generate sentences from a grammar.
What is a good parser generator for manipulating the actual grammar productions themselves? I want the parser generator to actually give me access to the productions (production objects?).
If I had a grammar akin to:
start_symbol ::= foo
foo ::= bar | baz
What is a good parser generator for:
- giving me the starting production symbol
- allow me to choose one production from RHS of the start symbol (
foo
in this case) - give me the production options for
foo
Clearly every parser has internal representations for productions and methods of associating the production with its RHS, but which parser would be easy to manipulate these internals?
Note: the blog entry linked to from the other SO question I mentioned has some sort of custom CFG parser. I want to use an actual grammar for a real parser, not generate my own grammar parser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写与解析器生成器接受的语法相匹配的语法应该很容易。 (使用开源解析器生成器,您应该能够从解析器生成器源代码中获取这样的语法;然后它们都具有自语法)。这样,您就可以解析解析器生成器接受的任何语法。
如果您想操作已解析的语法,您将需要一个相同的抽象语法树。您可以通过使用内置机制或添加的临时代码使大多数解析器生成器构建树。
It should be pretty easy to write a grammar, that matches the grammar that a parser generator accepts. (With an open source parser genrator, you ought to be able to fetch such a grammar from the parser generator source code; they all then to have self-grammars). With that, you can then parse any grammar the parser generator accepts.
If you want to manipulate the parsed grammar, you'll need an abstract syntax tree of same. You can make most parser generators build a tree, either by using built-in mechanisms or ad hoc code you add.