Search code examples
bisongraphvizyaccdot

How to print a YACC grammar graph starting from a specific node?


I have a vast YACC grammar for processing a family of related standards. I want to print its graph with bison --graph command, but the generated .dot file has over 40 thousand lines.

The graph is so big, xdot and dot tools are unable to render it. I finally managed to generate an output with sfdp, but the resulting image has over 50MB and is simply unintelligible.

Resulting grammar graph

I am only interested in visualizing a part of the grammar, preferably a subset starting from a specific grammar rule. Is there a way to add such constraints to the graph generation or rendering?


Solution

  • You can restrict a grammar to the subset starting at a nonterminal by adding

    %start the_nonterminal
    

    You'll get lots of useless production and useless non-terminal warnings, but you'll still get the graph.

    If you want to restrict it to a single production of a non-terminal, you could temporarily introduce a new start non-terminal for only that production (assuming that the grammar for the original non-terminal is not recursive).