Package schrodinger :: Package application :: Package desmond :: Package antlr3 :: Module dottreegen
[hide private]
[frames] | no frames]

Module dottreegen

@package antlr3.dottreegenerator @brief ANTLR3 runtime package, tree module

This module contains all support classes for AST construction and tree parsers.

Classes [hide private]
  DOTTreeGenerator
A utility class to generate DOT diagrams (graphviz) from arbitrary trees.
Functions [hide private]
 
toDOT(tree, adaptor=None, treeST=DOTTreeGenerator._treeST, edgeST=DOTTreeGenerator._edgeST)
Generate DOT (graphviz) for a whole tree not just a node.
Function Details [hide private]

toDOT(tree, adaptor=None, treeST=DOTTreeGenerator._treeST, edgeST=DOTTreeGenerator._edgeST)

 

Generate DOT (graphviz) for a whole tree not just a node.
For example, 3+4*5 should generate:

digraph {
    node [shape=plaintext, fixedsize=true, fontsize=11, fontname="Courier",
        width=.4, height=.2];
    edge [arrowsize=.7]
    "+"->3
    "+"->"*"
    "*"->4
    "*"->5
}

Return the ST not a string in case people want to alter.

Takes a Tree interface object.

Example of invokation:

    import antlr3
    import antlr3.extras

    input = antlr3.ANTLRInputStream(sys.stdin)
    lex = TLexer(input)
    tokens = antlr3.CommonTokenStream(lex)
    parser = TParser(tokens)
    tree = parser.e().tree
    print tree.toStringTree()
    st = antlr3.extras.toDOT(t)
    print st