问题描述
限时送ChatGPT账号..我是 ANTLR4 的新手,当我第一次在命令行中尝试它时,我使用的是带有 gui
参数的 grun
.现在我正在开发一个 Java 应用程序,我想在执行我的 Java 程序时显示相同的对话框.
I am new to ANTLR4, when I was first trying it out in command line I was using the grun
with gui
parameter. Now I am developing a Java application and I want to display the same dialog while executing my Java program.
我成功生成了 ParseTree,我可以浏览它.但我也想显示它.我认为它与 TreeViewer
类有关,但我不知道如何使用它.
I generated the ParseTree successfully, and I can navigate through it. But I want to display it as well. I think it has something to do with TreeViewer
class but I couldn't figure out how to use it.
谢谢
推荐答案
TreeViewer 是一个 Swing 组件,因此您应该能够将它添加到任何其他 SwingComponent,例如 JPanel.
TreeViewer is a Swing Component so you should be able to add it to any other SwingComponent, e.g a JPanel.
要实例化 TreeViewer(List
,您必须提供:
To instantiate a TreeViewer(List<String> rules, Tree tree)
you will have to provide:
null
,但使用 Parser.getRuleNames()
的结果会产生更好的结果一棵树,它是您解析的结果(类似于 XXXContext
).
a complete list of rule names, you can use null
here, but using the result of Parser.getRuleNames()
produces a better result
a tree, which is the result of your parsing (something like XXXContext
).
这篇关于使用 Java 在 ANTLR4 中绘制解析树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论