I’ve written a simple top down parser using c#. It’s a console application. I’d like the parser could save, at the end of the computation, an image file of the parse tree. I think I could use graphviz, but I’d like to know your opinion.
Thanks.
I’ve written a simple top down parser using c#. It’s a console application. I’d
Share
You could use SVG as an alternative to DOT/Graphviz; both are probably equally good.
In either case, it should be pretty easy to walk the parse tree and produce output that will control the drawing of the graph. If the tree is constructed explicitly, a recursive walk should be easy to implement. If the tree isn’t constructed, you’ll need to generate the graph nodes on the fly as you parse.
For the DMS Software Reengineering Toolkit, which constructs explicit ASTs, we do something simpler: walk the tree, and simply print out the root noot on one line, and its children on idented seperate lines of text. We do this in a LISP style format (for historical reasons) and an XML style format (much requested). The effort to code this if you can do a recursive tree walk is probably about an hour.
It isn’t a pretty as a graph drawing, but it doesn’t suffer from the problem of drawing huge graphs… just from getting huge text outputs, but those you can navigate with less or perl.
Even a small AST can have lots of nodes, and thus swamp your ability to draw/comprehend with graphics. My experience is that an AST has roughly 5-8 nodes per source line.
For the following 22-line PLSQL code:
Here’s a sample output, 180 tree nodes (note source position information for each node):