使用 Java 在 ANTLR4 中绘制解析树

编程入门 行业动态 更新时间:2024-10-17 16:18:45
本文介绍了使用 Java 在 ANTLR4 中绘制解析树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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 rules, Tree tree),您必须提供:

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:关键词]

本文发布于:2023-04-20 06:48:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/979999.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!