本文介绍了ANTLR4-DotGenerator示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里可以找到如何在ANTLR4中使用org.antlr.v4.tool.DotGenerator的示例?

Where I can find example how to use org.antlr.v4.tool.DotGenerator in ANTLR4?

据我了解,它取代了ANTLR4中的DOTTreeGenerator.

As I understand, it replaces DOTTreeGenerator in ANTLR4.

推荐答案

我也对您的问题的回答感兴趣,但尚未找到完全令人信服的答案.

I am also interested in an answer to your question and didn't find a fully convincing one yet.

假设您有兴趣在此处显示ParseTree,这是至少获得视觉表示的另一种方法:

Assuming that you are interested in Displaying the ParseTree here is an alternative way to at least get a visual representation:

  /**
   * show the given Tree Viewer
   * @param tv
   */
public int showTreeViewer(TreeViewer tv) {
  JPanel panel = new JPanel();
  tv.setScale(2);
  panel.add(tv);
  return JOptionPane.showConfirmDialog(null, panel, "ParseTree", 
    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
} 

 // http://stackoverflow.com/questions/30134121/drawing-parse-tree-in-antlr4-using-java/30137407#30137407
 ParseTree tree=rulesContext;
 List<String> ruleNames=Arrays.asList(parser.getRuleNames());
 // http://stackoverflow.com/questions/34832518/antlr4-dotgenerator-example
 TreeViewer tv=new TreeViewer(ruleNames,tree);
 showTreeViewer(tv);

这篇关于ANTLR4-DotGenerator示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 12:40