如何从语法中生成代码示例?(How to generate code samples from a grammar?)
我可以访问语法,并希望使用它来生成遵循语法的代码示例。
是否有一些现有工具可以做到这一点? 如果没有,那么正确的方法是什么?
I have access to a grammar, and want to use it to generate code samples that follow the grammar.
Is there some existing tool that does this? If not, what is the right approach?
最满意答案
您可以尝试mutt,或者此处列出的某些工具可能会满足您的需求。
如果你想自己实现一个文本生成器,你可以随机选择当前符号的可能扩展并沿着路径走,直到你不能再多或达到一个限制,然后尝试选择一个终结符号(如果有的话)
You could try mutt or some of the tools listed here might do what you are looking for.
If you wanted to implement a text generator yourself, you could randomly select a possible expansion of the current symbol and go down the path until you cannot any more or reached a limit, then try to select a terminator symbol if available
更多推荐
发布评论