Package org.snt.inmemantlr.tree
Class ParseTree
- java.lang.Object
-
- org.snt.inmemantlr.tree.ParseTree
-
public class ParseTree extends java.lang.Object
an abstract syntax tree
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
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.java.util.Set<ParseTreeNode>
getLeafs()
get leaf nodesjava.util.List<ParseTreeNode>
getNodes()
get all nodesParseTreeNode
getRoot()
get root nodeParseTree
getSubtree(ParseTree subtree)
get subtreejava.util.Set<ParseTree>
getSubtrees(java.util.function.Predicate<ParseTreeNode> p)
get subtree with the root node identified by pint
hashCode()
boolean
hasSubtree(ParseTree subtree)
check the presence of subree in the current treeParseTreeNode
newNode(ParseTreeNode parent, java.lang.String nt, java.lang.String label, int sidx, int eidx, int line, int charPositionInLine)
create new ast nodeboolean
removeSubtree(ParseTree subtree)
remove subtree from astboolean
replaceSubtree(ParseTree oldTree, ParseTree newTree)
replace oldTree by newTreejava.lang.String
toDot()
generate dot representation from astjava.lang.String
toJson()
generate JSON representation from astvoid
topoSort()
java.lang.String
toXml()
generate XML representation from ast
-
-
-
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 nodelabel
- 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 nodent
- name of node to be createdlabel
- value of node to be createdsidx
- start indexeidx
- end indexline
- linecharPositionInLine
- 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 replacednewTree
- 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 classjava.lang.Object
-
topoSort
public void topoSort()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
-