Class ParseTree


  • public class ParseTree
    extends java.lang.Object
    an abstract syntax tree
    • Constructor Detail

      • ParseTree

        public ParseTree​(java.lang.String nt,
                         java.lang.String label)
        constructor create a new abstract syntax tree
        Parameters:
        nt - name of root non-terminal node
        label - value of root non-terminal node
      • ParseTree

        public ParseTree​(ParseTree tree)
        constructor copy constructor
        Parameters:
        tree - tree to be duplicated
    • Method Detail

      • getRoot

        public ParseTreeNode getRoot()
        get root node
        Returns:
        root node
      • newNode

        public ParseTreeNode newNode​(ParseTreeNode parent,
                                     java.lang.String nt,
                                     java.lang.String label,
                                     int sidx,
                                     int eidx,
                                     int line,
                                     int charPositionInLine)
        create new ast node
        Parameters:
        parent - parent node
        nt - name of node to be created
        label - value of node to be created
        sidx - start index
        eidx - end index
        line - line
        charPositionInLine - character position in line
        Returns:
        newly created node
      • getLeafs

        public java.util.Set<ParseTreeNode> getLeafs()
        get leaf nodes
        Returns:
        set of leaf nodes
      • getNodes

        public java.util.List<ParseTreeNode> getNodes()
        get all nodes
        Returns:
        list of ast nodes
      • toDot

        public java.lang.String toDot()
        generate dot representation from ast
        Returns:
        dot format string
      • toJson

        public java.lang.String toJson()
        generate JSON representation from ast
        Returns:
        JSON format string
      • toXml

        public java.lang.String toXml()
        generate XML representation from ast
        Returns:
        XML format string
      • replaceSubtree

        public boolean replaceSubtree​(ParseTree oldTree,
                                      ParseTree newTree)
        replace oldTree by newTree
        Parameters:
        oldTree - tree to be replaced
        newTree - tree replacement
        Returns:
        true when subtree replacement was successful, false otherwise
      • removeSubtree

        public boolean removeSubtree​(ParseTree subtree)
        remove subtree from ast
        Parameters:
        subtree - to be removed
        Returns:
        true when removal was succesful, false otherwise
      • getDominatingSubtrees

        public java.util.Set<ParseTree> getDominatingSubtrees​(java.util.function.Predicate<ParseTreeNode> p)
        find dominant subtrees, i.e., subtrees where the distance of the subtree root node to the ast root node is minimal.
        Parameters:
        p - predicate to search for the dominating subtree root node
        Returns:
        set of dominating subtrees
      • getSubtrees

        public java.util.Set<ParseTree> getSubtrees​(java.util.function.Predicate<ParseTreeNode> p)
        get subtree with the root node identified by p
        Parameters:
        p - predicate for identifying the root node
        Returns:
        set of ast nodes
      • hasSubtree

        public boolean hasSubtree​(ParseTree subtree)
        check the presence of subree in the current tree
        Parameters:
        subtree - tree whose presence is checked
        Returns:
        true if subtree is present in actual one, false otherwise
      • getSubtree

        public ParseTree getSubtree​(ParseTree subtree)
        get subtree
        Parameters:
        subtree - tree whose presence is checked
        Returns:
        subree
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • topoSort

        public void topoSort()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object