xrel.parser
Class SimpleNode

java.lang.Object
  |
  +--xrel.parser.SimpleNode
All Implemented Interfaces:
java.lang.Cloneable, Node
Direct Known Subclasses:
ASTAs, ASTCase, ASTComma, ASTEmpty, ASTExportTp, ASTIdentifier, ASTImportSt, ASTOperator, ASTPar, ASTProgram, ASTStatementList, ASTString, ASTStringLiteral, ASTSwitchCase, ASTTag, ASTTypeDecl

public class SimpleNode
extends java.lang.Object
implements Node, java.lang.Cloneable


Field Summary
protected  Node[] children
           
protected  Token first
          Modified
protected  int id
           
protected  Token last
          Modified
protected  Node parent
           
protected  XRelParser parser
           
protected  java.util.HashSet Vars
          variables annotated on the value.
 
Constructor Summary
SimpleNode(int i)
          The standard constructor.
SimpleNode(XRelParser p, int i)
          This constructor lets you to specify the parser.
 
Method Summary
 void annotateValue(java.util.HashSet newSet)
          Associate the node with the specified set of variables.
 void bindAll()
           
 java.lang.Object childrenAccept(XRelParserVisitor visitor, java.lang.Object data)
          Accept the visitor.
protected  java.lang.Object clone()
          Clones this node.
 void dumpIntFlat(java.io.PrintStream out)
          Writes a tree in a internal flat representation.
 void dumpIntTree(java.io.PrintStream out, java.lang.String prefix)
          Writes out to the stream "out" the subtree of this node.
 void eraseAnnotations()
          Cleans the current node and its subtree from variable annotations.
 void eraseSubtreeAnnotations()
          Cleans the subtree of the current node from variable annotations.
 void exportExpression(java.lang.String filename, SymTable st)
          Exports to the stream "out" the subtree of this node in an XML format.
 Token getFirstToken()
          Returns the first token associated to this node.
 Token getLastToken()
          Returns the last token associated to this node.
 java.lang.String getPattern()
           
 java.lang.Object jjtAccept(XRelParserVisitor visitor, java.lang.Object data)
          Accept the visitor.
 void jjtAddChild(Node n, int i)
          Adds n to the children list of the current node.
 void jjtClose()
          This method is called after all the child nodes have been added.
 Node jjtGetChild(int i)
          This method returns a child node.
 int jjtGetNumChildren()
          Return the number of children the node has.
 Node jjtGetParent()
          This method is used to get the parent of the node.
 void jjtmAddChildExt(Node n, int i)
          Calls jjtAddChild and sets the parent pointer of the child.
 SimpleNode jjtmCloneSubtree()
          Clones this node and the whole subtree (by converse clone() makes only a copy of the node itself).
 void jjtmMoveChildren(Node dst, int from, int upto)
          Moves children subset [from,upto] from this node to dst.
 int jjtmSearchChild(SimpleNode node)
          Searches a child.
 void jjtmSetTokens(Token frst, Token lst)
          Sets the first and the last token of the current node.
 void jjtOpen()
          This method is called after the node has been made the current node.
 void jjtSetParent(Node n)
          This method is used to set the parent of the node.
 Token searchTokenFrom(java.lang.String tk, Token start)
          Searches a token with name tk from the token start.
 void showAnnotations(java.io.PrintStream out, java.lang.String prefix)
           
 java.lang.String toString()
          Returns a string representation of the node.
 java.lang.String toString(java.lang.String prefix)
          Returns a string representation of the node.
 void writeExpression(java.io.PrintStream out, java.lang.String prefix, SymTable st)
          Writes out to the stream "out" the subtree of this node in a human-readable structured format.
 void writePattern(java.io.PrintStream out)
          Writes a tree in a compact human-readable form.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parent

protected Node parent

children

protected Node[] children

id

protected int id

parser

protected XRelParser parser

first

protected Token first
Modified

last

protected Token last
Modified

Vars

protected java.util.HashSet Vars
variables annotated on the value. Used by automata
Constructor Detail

SimpleNode

public SimpleNode(int i)
The standard constructor. It accepts one only argument: the constant that identifies the subclass.
Parameters:
i - the constant that identifies the subclass

SimpleNode

public SimpleNode(XRelParser p,
                  int i)
This constructor lets you to specify the parser.
Parameters:
p - the parser
i - the constant that identifies the subclass
Method Detail

jjtSetParent

public void jjtSetParent(Node n)
Description copied from interface: Node
This method is used to set the parent of the node.
Specified by:
jjtSetParent in interface Node

jjtGetParent

public Node jjtGetParent()
Description copied from interface: Node
This method is used to get the parent of the node.
Specified by:
jjtGetParent in interface Node

jjtAddChild

public void jjtAddChild(Node n,
                        int i)
Adds n to the children list of the current node. Specifically if "i" is inside the range of the existing children it will replace the i-th node with n, while if "i" is greater than the index of the last child it will append the specified node n to the existing children to the i-th position. Note that the children list will be expanded to contain however at least i+1 nodes.
Specified by:
jjtAddChild in interface Node
Parameters:
n - the node to become child of the current node
i - the position in the children list where to put n
See Also:
Node.jjtAddChild(xrel.parser.Node, int)

jjtGetChild

public Node jjtGetChild(int i)
Description copied from interface: Node
This method returns a child node. The children are numbered from zero, left to right.
Specified by:
jjtGetChild in interface Node

jjtGetNumChildren

public int jjtGetNumChildren()
Description copied from interface: Node
Return the number of children the node has.
Specified by:
jjtGetNumChildren in interface Node

jjtAccept

public java.lang.Object jjtAccept(XRelParserVisitor visitor,
                                  java.lang.Object data)
Accept the visitor.
Specified by:
jjtAccept in interface Node

childrenAccept

public java.lang.Object childrenAccept(XRelParserVisitor visitor,
                                       java.lang.Object data)
Accept the visitor.

toString

public java.lang.String toString()
Returns a string representation of the node. You can override this method in subclasses of SimpleNode to customize the way the node appears when the tree is dumped. If your output uses more than one line you should override toString(String), otherwise overriding toString() is probably all you need to do.
Overrides:
toString in class java.lang.Object
Returns:
the string associated to the node
See Also:
Object.toString()

toString

public java.lang.String toString(java.lang.String prefix)
Returns a string representation of the node. You can override this method in subclasses of SimpleNode to customize the way the node appears when the tree is dumped. It's specially useful when your output uses more than one line (if your output uses one only line overriding toString() is probably all you need to do).
Parameters:
prefix - a prefix for the string
Returns:
the string associated to the node

jjtOpen

public void jjtOpen()
Description copied from interface: Node
This method is called after the node has been made the current node. It indicates that child nodes can now be added to it.
Specified by:
jjtOpen in interface Node

jjtClose

public void jjtClose()
Description copied from interface: Node
This method is called after all the child nodes have been added.
Specified by:
jjtClose in interface Node

getFirstToken

public Token getFirstToken()
Returns the first token associated to this node. Note that some transformation on the the syntax tree loose this information.
Returns:
the first token

getLastToken

public Token getLastToken()
Returns the last token associated to this node. Note that some transformations on the syntax tree loose this information.
Returns:
the last token

writeExpression

public void writeExpression(java.io.PrintStream out,
                            java.lang.String prefix,
                            SymTable st)

Writes out to the stream "out" the subtree of this node in a human-readable structured format. While dumpIntTree() is used to write the original syntax tree, this function is used to write XML values or output expressions.

N.B.:

Parameters:
out - the stream where to dump out
prefix - a string of prefix
See Also:
dumpIntTree(PrintStream out, String prefix)

exportExpression

public void exportExpression(java.lang.String filename,
                             SymTable st)

Exports to the stream "out" the subtree of this node in an XML format.

N.B.:

Parameters:
out - the stream where to dump out
prefix - a string of prefix

writePattern

public void writePattern(java.io.PrintStream out)

Writes a tree in a compact human-readable form.

N.B.:

Parameters:
out - the stream where to print out

getPattern

public java.lang.String getPattern()

dumpIntTree

public void dumpIntTree(java.io.PrintStream out,
                        java.lang.String prefix)
Writes out to the stream "out" the subtree of this node.
Parameters:
out - the stream where to dump out
prefix - a string of prefix

dumpIntFlat

public void dumpIntFlat(java.io.PrintStream out)

Writes a tree in a internal flat representation. Flat means that description stands in a single row. Internal means that the internal tree structure is shown istead of a more human-readable format.

For example "a[],b[] | c[]" is represented as

Par[ Comma[ Tag "a"[Empty], Tag "b"[Empty] ], Tag "c"[Empty] ]

N.B.:

Parameters:
out - the stream where to print out

annotateValue

public void annotateValue(java.util.HashSet newSet)
Associate the node with the specified set of variables. A check is made if the node is a tag
Parameters:
newSet -  

eraseSubtreeAnnotations

public void eraseSubtreeAnnotations()

Cleans the subtree of the current node from variable annotations. Note that it doesn't clean the annotations on the current node, only on the nodes of the subtree.

See Also:
eraseAnnotations()

eraseAnnotations

public void eraseAnnotations()

Cleans the current node and its subtree from variable annotations. Note that it cleans the annotations both from the current node and from the nodes in the subtree.

See Also:
eraseSubtreeAnnotations()

showAnnotations

public void showAnnotations(java.io.PrintStream out,
                            java.lang.String prefix)

bindAll

public void bindAll()

searchTokenFrom

public Token searchTokenFrom(java.lang.String tk,
                             Token start)
Searches a token with name tk from the token start.

N.B.: I've added this to search "as".

Parameters:
tk - the name of the token to search
start - where to start to search
Returns:
the found token or null

jjtmCloneSubtree

public SimpleNode jjtmCloneSubtree()

Clones this node and the whole subtree (by converse clone() makes only a copy of the node itself).

Returns:
the root of the new subtree (the copy of the current node)

clone

protected java.lang.Object clone()
Clones this node. References to the parent and to the children are not changed.
Overrides:
clone in class java.lang.Object
Returns:
the copy of the object
See Also:
Object.clone()

jjtmAddChildExt

public void jjtmAddChildExt(Node n,
                            int i)
Calls jjtAddChild and sets the parent pointer of the child. You should use this function instead of jjtAddChild.
Parameters:
n - the node that will be child of the current node
i - the position inside the children list.

jjtmMoveChildren

public void jjtmMoveChildren(Node dst,
                             int from,
                             int upto)
Moves children subset [from,upto] from this node to dst.
Parameters:
dst - node to which move
from - index of the first child to move
upto - index of the last child to move

jjtmSetTokens

public void jjtmSetTokens(Token frst,
                          Token lst)
Sets the first and the last token of the current node.
Parameters:
frst - the first token
lst - the last token

jjtmSearchChild

public int jjtmSearchChild(SimpleNode node)
Searches a child. When not found it returns -1.
Parameters:
node - the node to find
Returns:
the index of the child or -1 when it doesn't exist