ANTLR4 - DotGenerator example [duplicate]

回眸只為那壹抹淺笑 提交于 2020-01-06 02:14:30

问题


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

As I understand, it replaces DOTTreeGenerator in ANTLR4.


回答1:


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

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


来源:https://stackoverflow.com/questions/34832518/antlr4-dotgenerator-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!