Thursday, June 30, 2011

Visualizing parsers

Parcon 0.1.22 is out, with a really cool new feature: parser visualization. Parcon now includes the ability to generate graphs from parsers that describe what those parsers do.

There are still some kinks to be worked out, and I'll save a detailed blog post on Parcon graphing for when those are fixed, but the basic thing works. For example, the expression evaluator Parcon example (which is present on the PyPI page for Parcon), when converted to a graph via this:
term.graph().draw("test-graph2.png")

results in this (click on the image to view a larger version):



In order for graphing to work, you have to have Graphviz installed, and specifically you need to have the dot program installed. You do not, however, need this installed to use Parcon, and in fact, you don't even need it to call graph(); you just need it when you actually call draw().

You'll probably notice some of the kinks. Two of the major ones are that InfixExpr doesn't display any representation of the functions it was passed, and the child parsers for Then and First are displayed out of order. Once I get those, and a few others, solved, I'll write a more detailed post on visualizing parsers with Parcon.

But you've got to admit, even as it is it's pretty cool.

2 comments:

  1. The site is down ATM. http://www.isup.me/http://www.opengroove.org/

    ReplyDelete
  2. Thanks for letting me know. It turned out it was due to a circuit breaker tripping. (I wrote a post a few hours ago on the blog explaining it.) It's back up now, though, thank goodness.

    ReplyDelete