public abstract class ASTNode extends Object
null
. The symbol (ø) is used to indicate that the variable is allowed to be
null
, and the symbol (¬ø) indicates that the variable will never be
null
.
ASTNodeIterator
through the abstract iterator()
method that
traverses its children in the order in which the code would be executed. If the node is composed
of declarative constructs rather than executable code, the iterator will traverse those
constructs in the order in which they appear in the source.
clone()
method such that it returns a deep copy of itself, except that
the line and byte offset of the copy are both set to -1
.
runPass(Pass)
method so that it simply calls the Pass
's
run(.)
method whose argument type is the type of the node.
String
representation of itself through the toString()
and
write(StringBuffer)
methods. Only the write(StringBuffer)
method need
be overridden by each node, as toString()
will simply invoke
write(StringBuffer)
to produce its result. (This is much more efficient than having
toString()
call its childrens' toString()
methods recursively through
the AST and concatenating them all together.) The String
produced will not be very
readable (e.g., it won't contain any new lines), but it will be compilable by the LBJava
compiler.
ASTNode
s will also contain more than one constructor. There will be one
constructor that includes all references to its children as well as line and byte offset
information, etc. This constructor is commonly used by the node's clone()
method. In
addition, there may be at least one constructor designed to be more useful for the JavaCUP
parser, taking TokenValue
s as input.Modifier and Type | Field and Description |
---|---|
int |
byteOffset
The byte offset from the beginning of the source file at which the source code represented by
this node is found.
|
int |
line
The line on which the source code represented by this node is found.
|
int |
nodeID
Stores the ID of this node as provided by
nextID . |
SymbolTable |
symbolTable
The table of variable types representing this node's scope.
|
Constructor and Description |
---|
ASTNode()
Default constructor.
|
ASTNode(int line,
int byteOffset)
Initializing constructor.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Creates a new object with the same primitive data, and recursively creates new member data
objects as well.
|
abstract ASTNodeIterator |
iterator()
Returns an iterator used to successively access the children of this node.
|
abstract void |
runPass(Pass pass)
Ensures that the correct
run() method is called for this type of node. |
String |
toString()
Calls the
write(StringBuffer) method to produce a string representation of this
node. |
abstract void |
write(StringBuffer buffer)
Writes a string representation of this
ASTNode to the specified buffer. |
public int nodeID
nextID
.public int line
public int byteOffset
public SymbolTable symbolTable
public ASTNode()
public ASTNode(int line, int byteOffset)
super
operator from
every other node.line
- The line on which the source code represented by this node is found.byteOffset
- The byte offset from the beginning of the source file at which the source
code represented by this node is found.public abstract ASTNodeIterator iterator()
public Object clone()
public abstract void runPass(Pass pass)
run()
method is called for this type of node.pass
- The pass whose run()
method should be called.public String toString()
write(StringBuffer)
method to produce a string representation of this
node.public abstract void write(StringBuffer buffer)
ASTNode
to the specified buffer. The
representation written is parsable by the LBJava compiler, but not very readable.buffer
- The buffer to write to.Copyright © 2016. All rights reserved.