开发者

Which parser generator would be useful for manipulating the productions themselves?

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 st开发者_JAVA技巧art 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜