Antlrworks provides a visualized parsed tree for the input source code file. I was wondering if there is any equavalent tool for javacc & jtb thanks
Asked
Active
Viewed 141 times
1 Answers
2
Walk the tree. Spit out nodes and arcs in graphviz ("dot") format. Invoke graphviz on the result.
This won't be very useful for more than a hundred nodes, because it isn't very dense.
Remarkably, a more scalable way to is print a nested S-expression, in the following format:
<depth_from_root*spaces> ( <nodetype> <newline>
<childnode1_as_S-expression>
<childnode2_as_S-expression>
...
<childnodeN_as_S-expression>
)<nodetype>
This in effect prints the tree sideways, e.g., with the root at the left and children to the right. You can print out very big trees this way, and still be able to read them (if you can scroll up and down through the text).
As an example: for a*(b+c)-d:
(-
(*
(+
(variable b)
(variable c)
)+
)*
(constant 1)
)-
This is also easily done with a tree walk. You can easily make the printed version more dense, or add more information.
See examples of both of these, here.

Community
- 1
- 1

Ira Baxter
- 93,541
- 22
- 172
- 341
-
I think this is a kind of ast, not parsed tree – Hai Pham Jun 30 '15 at 05:30
-
It doesn't matter if it is an AST or a parse tree; this technique works just fine. – Ira Baxter Jun 30 '15 at 05:41
-
Yep, I agree. Is there any tool/plugin to visualize based on JavaCC & JTB grammar? In the case developing from scratch, graphviz is a good option. Thank you so much for your recommendation – Hai Pham Jun 30 '15 at 09:11
-
The point is that both of these solutions are really easy to implement. – Ira Baxter Jun 30 '15 at 10:54
-
Thanks. This will be an answer if there is no tool/plugin available – Hai Pham Jun 30 '15 at 11:38