ANTLR3 运行时元数据
在解析过程中如何知道当前匹配的是哪条规则? 我想使用规则名称自动构建表示解析输入的 XML(或其他对象层次结构),而不需要使用语法操作或树。
这可能吗?
非常感谢, 雅科夫
How can I know during parsing which rule is currently matched?
I'd like to automatically build an XML (or other objectal hierarchy) representing the parsed input, using rule names, without the need of using grammar actions or trees.
Is this possible?
Many thanks,
Yaakov
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AFAIK,那是不可能的。但为什么不使用 ANTLR 的内置树结构呢?在语法的
options{ }
部分中,添加output=AST;
并在适用的情况下使用重写规则。请参阅: http:// /www.antlr.org/wiki/display/~admin/2008/11/30/Example+tree+rewriting+with+patternsAFAIK, that is not possible. But why don't you use ANTLR's built in tree construction? In the
options{ }
part of your grammar, addoutput=AST;
and use rewrite rules where applicable. See: http://www.antlr.org/wiki/display/~admin/2008/11/30/Example+tree+rewriting+with+patterns