java 画树,使用Java在ANTLR4中绘制解析树

在ANTLR4中,使用grun命令行工具时可以启用GUI参数展示解析树。现在你希望在Java应用程序中实现相同功能。关键在于使用TreeViewer类,它是一个Swing组件,可以添加到任何其他Swing组件上。要创建TreeViewer,你需要提供规则名称列表(如Parser.getRuleNames()的结果)和解析树(如XXXContext)。这将帮助你在Java程序执行时显示解析树。
摘要由CSDN通过智能技术生成

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.

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.

Thanks

解决方案

TreeViewer is a Swing Component so you should be able to add it to any other SwingComponent, e.g a JPanel.

To instantiate a TreeViewer(List rules, Tree tree) you will have to provide:

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).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值