This question already has an answer here:
- ANTLR4 parse tree to DOT using DOTGenerator 2 answers
Where I can find example how to use org.antlr.v4.tool.DotGenerator in ANTLR4?
As I understand, it replaces DOTTreeGenerator in ANTLR4.
This question already has an answer here:
Where I can find example how to use org.antlr.v4.tool.DotGenerator in ANTLR4?
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.
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);