Package tulip :: Package spec :: Module transformation :: Class Tree
[frames] | no frames]

Class Tree


Abstract syntax tree as a graph data structure.

Use this as a scaffold for syntactic manipulation. It makes traversals and graph rewriting easier, so it is preferred to working directly with the recursive AST classes.

The attribute self.root is the tree's root Node.

Nested Classes

Inherited from networkx.classes.multigraph.MultiGraph: edge_key_dict_factory

Inherited from networkx.classes.graph.Graph: adjlist_dict_factory, edge_attr_dict_factory, node_dict_factory

Instance Methods
 
__init__(self)
Initialize a graph with edges, name, graph attributes.
 
__repr__(self)
repr(x)
 
__str__(self)
Return the graph name.
 
to_recursive_ast(self, u=None)
 
add_subtree(self, leaf, tree)
Add the tree at node nd.
str
to_pydot(self, detailed=False)
Create GraphViz dot string from given AST.
 
write(self, filename, detailed=False)
Layout AST and save result in PDF file.

Inherited from networkx.classes.multidigraph.MultiDiGraph: add_edge, degree_iter, edges_iter, in_degree_iter, in_edges, in_edges_iter, is_directed, is_multigraph, out_degree_iter, out_edges, out_edges_iter, remove_edge, reverse, subgraph, to_directed, to_undirected

Inherited from networkx.classes.multigraph.MultiGraph: add_edges_from, edges, get_edge_data, has_edge, number_of_edges, remove_edges_from, selfloop_edges

Inherited from networkx.classes.digraph.DiGraph: add_node, add_nodes_from, clear, has_predecessor, has_successor, in_degree, neighbors, neighbors_iter, out_degree, predecessors, predecessors_iter, remove_node, remove_nodes_from, successors, successors_iter

Inherited from networkx.classes.graph.Graph: __contains__, __getitem__, __iter__, __len__, add_cycle, add_path, add_star, add_weighted_edges_from, adjacency_iter, adjacency_list, copy, degree, has_node, nbunch_iter, nodes, nodes_iter, nodes_with_selfloops, number_of_nodes, number_of_selfloops, order, size

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Methods
 
from_recursive_ast(cls, u)
Properties
set of Var variables
Return the set of variables in tree.

Inherited from networkx.classes.graph.Graph: name

Inherited from object: __class__

Method Details

__init__(self)
(Constructor)

 
Initialize a graph with edges, name, graph attributes.

Parameters
----------
data : input graph
    Data to initialize graph.  If data=None (default) an empty
    graph is created.  The data can be an edge list, or any
    NetworkX graph object.  If the corresponding optional Python
    packages are installed the data can also be a NumPy matrix
    or 2d ndarray, a SciPy sparse matrix, or a PyGraphviz graph.
name : string, optional (default='')
    An optional name for the graph.
attr : keyword arguments, optional (default= no attributes)
    Attributes to add to graph as key=value pairs.

See Also
--------
convert

Examples
--------
>>> G = nx.Graph()   # or DiGraph, MultiGraph, MultiDiGraph, etc
>>> G = nx.Graph(name='my graph')
>>> e = [(1,2),(2,3),(3,4)] # list of edges
>>> G = nx.Graph(e)

Arbitrary graph attribute pairs (key=value) may be assigned

>>> G=nx.Graph(e, day="Friday")
>>> G.graph
{'day': 'Friday'}

Overrides: object.__init__
(inherited documentation)

__repr__(self)
(Representation operator)

 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

 
Return the graph name.

Returns
-------
name : string
    The name of the graph.

Examples
--------
>>> G = nx.Graph(name='foo')
>>> str(G)
'foo'

Overrides: object.__str__
(inherited documentation)

add_subtree(self, leaf, tree)

 

Add the tree at node nd.

Parameters:
  • tree (Tree) - to be added, w/o copying AST nodes.
  • leaf (FOL.Node)

to_pydot(self, detailed=False)

 

Create GraphViz dot string from given AST.

Parameters:
  • ast (ASTNode)
Returns: str

Property Details

variables

Return the set of variables in tree.

Get Method:
unreachable.variables(self) - Return the set of variables in tree.
Type:
set of Var