kites.logic
Class ProgramRewrite

java.lang.Object
  extended by kites.logic.ProgramRewrite

public class ProgramRewrite
extends java.lang.Object

This class performs the actual rewriting. The method rewrite is given a node to rewrite and a rule to rewrite it with. It then builds a mapping between variables and their assignments and build a new tree according to the rule and the variable assignments.


Constructor Summary
ProgramRewrite()
           
 
Method Summary
private static ASTNode buildTree(ASTNode right, java.util.HashMap<java.lang.String,ASTNode> assignments)
          Build a new tree from the right-hand side of a rule and a map of variable assignments.
static ASTNode rewrite(ASTNode tree, ASTNode node, Rule rule)
          Rewrite a node using a specific rule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProgramRewrite

public ProgramRewrite()
Method Detail

buildTree

private static ASTNode buildTree(ASTNode right,
                                 java.util.HashMap<java.lang.String,ASTNode> assignments)
                          throws SyntaxErrorException
Build a new tree from the right-hand side of a rule and a map of variable assignments. Performed when a rewrite possibility was found.

Parameters:
right - The right-hand side of the rule to be applied
assignments - The map of variable assignments to be used
Returns:
The new tree
Throws:
SyntaxErrorException

rewrite

public static ASTNode rewrite(ASTNode tree,
                              ASTNode node,
                              Rule rule)
                       throws SyntaxErrorException
Rewrite a node using a specific rule. This is also used when not in program execution mode. The method builds a mapping between the variables used on the left-hand side of the rule and the respective content in the tree. It then goes on and builds a new tree out of the right-hand side of the rule and replaces the variables there using the previously built mapping.

Parameters:
tree - The tree to rewrite
node - The node to rewrite
rule - The rule to apply
Returns:
The rewritten tree
Throws:
SyntaxErrorException