All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----epp.Tree
Tree class is a class for describing a node of an abstract
syntax tree.
For example, an if statment will be described as
the following abstract syntax tree within EPP.
(if new Tree(:if, condition, then, else)
The portion that specifies the node type (:if, in this case)
is called a tag,  and all subtrees of a node (condition, then, else,
in this case) are called args.
A Tree is an immutable object.
You cannot modify tags and args.
(Programmers must be careful not to overwrite the contents of the
Tree array that the tree.args() method call returns.
If you do overwrite by mistake, it may cause a very confusing bug.)
Tree has a subclass named Identifier and
LiteralTree. All nodes of an abstract syntax tree are
expressed with one of the three classes, Tree,
Indentifier or LiteralTree.
Plug-ins can extend the syntax and introduce new types of nodes.
However, those nodes must also be expressed with on of the three classes
mentioned above.
By calling a method named tree.print() with an instance
tree of class Tree, an abstract syntax tree can be printed
in the form of an S-expression.
For example, if you parse following program,
	if (x == 0) System.out.println("Hello!");
the resulting abstract syntax tree will printed as follows.
      (if
       (==
        (id x)
        (literalTree int "0"))
       (expressionStatement
        (invokeLong
         (name
          (id System)
          (id out))
         (id println)
         (argumentList
          (literalTree string "Hello!"))))
       (emptyStatement))
For LiteralTree and Identifier,
tree.args() will always return an array of length zero.
Due to this design, recursive processing of a tree will be very
simple. For example, a method that counts the number of times
an if statement appears in a tree can simply be
defined as follows.
int countIf(Tree tree){
  int c = 0;
  if (tree.tag() == :if) c++;
  Tree[] args = tree.args();
  for (int i = 0; i < args.length; i++){
    c += countIf(args[i]);
  }
  return c;
}
Other than tags and args, the Tree class has additional
information such as line numbers.
If you wish to generate a tree with only the args value modified
while retaining other information, you use the modifyArgs
method.
	Tree[] newArgs = {...};
	Tree newTree = tree.modifyArgs(newArgs);
This is the same as the following program, except for the fact that
information of the tree, such as line numbers, will be copied to
newTree.
	Tree[] newArgs = {...};
	Tree newTree = new Tree(tree.tag(), newArgs);
The BackQuote plug-in is provided to make it easier to
write code that generates a large Tree.
Please refer to ../BackQuote.html
for further information.
You can cut and paste an abstract syntax tree that was printed by
tree.print() or the -tree option of epp, and use it
directly in the BackQuote macro.
The TreeVec class is provided since you will frequently use
a variable length array of Tree. This is more convenient than
using java.lang.Vector since you do not need to do any casting.
 
 Tree(Symbol)
	Tree(Symbol)
   Tree(Symbol, Tree)
	Tree(Symbol, Tree)
   Tree(Symbol, Tree, Tree)
	Tree(Symbol, Tree, Tree)
   Tree(Symbol, Tree, Tree, Tree)
	Tree(Symbol, Tree, Tree, Tree)
   Tree(Symbol, Tree, Tree, Tree, Tree)
	Tree(Symbol, Tree, Tree, Tree, Tree)
   Tree(Symbol, Tree, Tree, Tree, Tree, Tree)
	Tree(Symbol, Tree, Tree, Tree, Tree, Tree)
   Tree(Symbol, Tree, Tree, Tree, Tree, Tree, Tree)
	Tree(Symbol, Tree, Tree, Tree, Tree, Tree, Tree)
   Tree(Symbol, Tree, Tree, Tree, Tree, Tree, Tree, Tree)
	Tree(Symbol, Tree, Tree, Tree, Tree, Tree, Tree, Tree)
   Tree(Symbol, Tree[])
	Tree(Symbol, Tree[])
   Tree(Symbol, TreeVec)
	Tree(Symbol, TreeVec)
   
 args()
	args()
   beginningPoint()
	beginningPoint()
   endPoint()
	endPoint()
   idName()
	idName()
  Identifier.
   isTyped()
	isTyped()
   lineNumber()
	lineNumber()
   literalToken()
	literalToken()
  LiteralToken that describes the contents of a
LiteralTree if this node is a LiteralTree.
   main(String[])
	main(String[])
   modifyArgs(Tree[])
	modifyArgs(Tree[])
  Tree with only args of this node modified.
   modifyBeginningPoint(int)
	modifyBeginningPoint(int)
   modifyEndPoint(int)
	modifyEndPoint(int)
   modifyLineNumber(int)
	modifyLineNumber(int)
   modifyProperty(Symbol, Object)
	modifyProperty(Symbol, Object)
  Tree with the property of this node
modified.
   modifyTypeAndArgs(Type, Tree[])
	modifyTypeAndArgs(Type, Tree[])
  Tree with only types and args of this
node modified.
   nameEqual(Tree, Tree)
	nameEqual(Tree, Tree)
  Trees that have :name tags.
   nameToString()
	nameToString()
  Tree that have :name tags into a string.
   print()
	print()
  Opts.out in a human readable form.
   print(PrintWriter)
	print(PrintWriter)
   print(PrintWriter, String)
	print(PrintWriter, String)
   printProp(PrintWriter)
	printProp(PrintWriter)
   property(Symbol)
	property(Symbol)
   quoteString(String)
	quoteString(String)
  Identifier and LiteralToken.
   resetType()
	resetType()
  Tree with no type information.
   stringToNameTree(String)
	stringToNameTree(String)
   tag()
	tag()
   toString()
	toString()
  String without indentation.
   type()
	type()
   
 Tree
Tree
 public Tree(Symbol tag,
             Tree args[])
 Tree
Tree
 public Tree(Symbol tag,
             TreeVec args)
 Tree
Tree
public Tree(Symbol t)
 Tree
Tree
 public Tree(Symbol t,
             Tree a1)
 Tree
Tree
 public Tree(Symbol t,
             Tree a1,
             Tree a2)
 Tree
Tree
 public Tree(Symbol t,
             Tree a1,
             Tree a2,
             Tree a3)
 Tree
Tree
 public Tree(Symbol t,
             Tree a1,
             Tree a2,
             Tree a3,
             Tree a4)
 Tree
Tree
 public Tree(Symbol t,
             Tree a1,
             Tree a2,
             Tree a3,
             Tree a4,
             Tree a5)
 Tree
Tree
 public Tree(Symbol t,
             Tree a1,
             Tree a2,
             Tree a3,
             Tree a4,
             Tree a5,
             Tree a6)
 Tree
Tree
 public Tree(Symbol t,
             Tree a1,
             Tree a2,
             Tree a3,
             Tree a4,
             Tree a5,
             Tree a6,
             Tree a7)
 
 main
main
public static void main(String argv[])
 tag
tag
public Symbol tag()
 args
args
public Tree[] args()
 lineNumber
lineNumber
public int lineNumber()
 beginningPoint
beginningPoint
public int beginningPoint()
 endPoint
endPoint
public int endPoint()
 type
type
public Type type()
 property
property
public Object property(Symbol key)
 idName
idName
public Symbol idName()
Identifier.
Otherwise, a fatal error will occur.
 literalToken
literalToken
public LiteralToken literalToken()
LiteralToken that describes the contents of a
LiteralTree if this node is a LiteralTree.
Otherwise, a fatal error will occur.
 modifyArgs
modifyArgs
public Tree modifyArgs(Tree args[])
Tree with only args of this node modified.
All information other than args, such as line number information, will be
copied to the new Tree.
 isTyped
isTyped
public boolean isTyped()
 modifyTypeAndArgs
modifyTypeAndArgs
 public Tree modifyTypeAndArgs(Type type,
                               Tree args[])
Tree with only types and args of this
node modified. All other information, such as line number information,
will be copied to the new Tree. If this Tree
already has type information, a fatal error will occur.
 resetType
resetType
public Tree resetType()
Tree with no type information.
All information other than type information are copied from the original
Tree to the new Tree.
 modifyProperty
modifyProperty
 public Tree modifyProperty(Symbol key,
                            Object val)
Tree with the property of this node
modified. All information other than additonal information are copied
from the original Tree to the new Tree.
 modifyLineNumber
modifyLineNumber
public Tree modifyLineNumber(int x)
 modifyBeginningPoint
modifyBeginningPoint
public Tree modifyBeginningPoint(int x)
 modifyEndPoint
modifyEndPoint
public Tree modifyEndPoint(int x)
 nameEqual
nameEqual
 public static boolean nameEqual(Tree name1,
                                 Tree name2)
Trees that have :name tags.
 nameToString
nameToString
public String nameToString()
Tree that have :name tags into a string.
For example, (name (id a) (id b) (id c)) will become "a.b.c".
 print
print
public Tree print()
Opts.out in a human readable form.
Used for debugging.
If you write tree.print(), the tree will be printed
with indentations so that it will be easier to read.
This method returns itself as the return value.
Type information and line number information will also be printed according to the options specified to the epp command on invocation.
If these information are not attached, you may cut and paste the printed
results and use them directly as part of the BackQuote macro.
 print
print
public Tree print(PrintWriter out)
 print
print
 public void print(PrintWriter out,
                   String indent)
 printProp
printProp
public void printProp(PrintWriter out)
 toString
toString
public String toString()
String without indentation.
 quoteString
quoteString
public static String quoteString(String in)
Identifier and LiteralToken.
Examples: "foo" -> "\"foo\"" "\n" -> "\"\\n\"" "\"" => "\"\\\"\""
 stringToNameTree
stringToNameTree
public static Tree stringToNameTree(String str)
All Packages Class Hierarchy This Package Previous Next Index