1

I am using IntelliJ Idea Plugin for ANTLR v4 which previews the parse tree. But the preview is quite difficult to interpret when a large binary tree is generated in case of large code.

Is there any alternate way to view the same or generate the output in any other format like PDF etc.

example for large code base

  • I see there is a request for PDF format for the view in the plugin issue tracker: https://github.com/antlr/intellij-plugin-v4/issues/189 – Andrey Apr 05 '18 at 06:27
  • 1
    You also can try to generate a .dot file from parse tree with visitor and render it with https://www.graphviz.org/ – Ivan Kochurkin Apr 05 '18 at 19:39

2 Answers2

3

There are alternatives, if you are willing to switch tools. For example the ANTLR4 extension for Visual Studio Code can show an interactive parse tree (you can view it in different layouts, you can collapse nodes to hide uninteresting parts etc.). Below is a picture of the tree or watch an animation on my homepage.

enter image description here

This generated graph can be stored as SVG along with built-in or custom CSS to style it.

Community
  • 1
  • 1
Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
  • thanks, here are some links for those intersted, https://github.com/mike-lischke/vscode-antlr4/blob/master/doc/graphical-visualizations.md https://github.com/mike-lischke/vscode-antlr4/blob/master/doc/grammar-debugging.md – HoseinGhanbari Apr 28 '20 at 17:52
1

Antlr provides an output of a parse tree in lisp format. ParseTree tree = parser.yourRule() and then output it with tree.toString(parser). Then a lisp tree will be generated. You can also generate a tree in json format with Gson. However, these trees are not so 'visualized', but great for further processing.

Shawn
  • 35
  • 9