step9
Class i

java.lang.Object
  extended by step9.i
All Implemented Interfaces:
Visitor
Direct Known Subclasses:
bi

public class i
extends Object
implements Visitor

rewrites Node trees as typed trees. Infrastructure and support for i.IntegerT. Naming convention: the suffix T indicates a type.


Nested Class Summary
static class i.IAdd
          add two i.IntegerT trees.
static class i.IAnd
          bit-and two i.IntegerT trees.
static class i.IDiv
          divide two i.IntegerT trees.
static class i.ILsh
          left shift two i.IntegerT trees.
static class i.IMinus
          sign-change an i.IntegerT tree.
static class i.IMod
          remainder of two i.IntegerT trees.
static class i.IMul
          multiply two i.IntegerT trees.
static class i.INeg
          bit-complement an i.IntegerT tree.
static class i.IntegerT
          base class for integer operations, itself used to type an Integer leaf.
static class i.IOr
          bit-or two i.IntegerT trees.
static class i.IPrint
          print an i.IntegerT object.
static class i.IRsh
          right shift two i.IntegerT trees.
static class i.ISub
          subtract two i.IntegerT trees.
static class i.IXor
          bit-xor two i.IntegerT trees.
static class i.T
          base class for typed branch nodes.
 
Field Summary
protected  HashMap _rules
          maps class to array of Rule.
protected  PrintStream out
          print action stream.
 
Constructor Summary
i()
           
 
Method Summary
static String classname(Object o)
          returns simplified classname.
 Object IAdd(ArrayList sub)
          factory method: add two i.IntegerT trees.
 Object IAnd(ArrayList sub)
          factory method: bit-and two i.IntegerT trees.
 Object IDiv(ArrayList sub)
          factory method: divide two i.IntegerT trees.
 Object ILsh(ArrayList sub)
          factory method: left shift two i.IntegerT trees.
 Object IMinus(ArrayList sub)
          factory method: sign-change an i.IntegerT tree.
 Object IMod(ArrayList sub)
          factory method: remainder of two i.IntegerT trees.
 Object IMul(ArrayList sub)
          factory method: multiply two i.IntegerT trees.
 Object INeg(ArrayList sub)
          factory method: bit-complement an i.IntegerT tree.
 i.IntegerT IntegerT(Integer i)
          factory method: type an Integer leaf.
 Object IOr(ArrayList sub)
          factory method: bit-or two i.IntegerT trees.
 Object IPrint(i.IntegerT sub)
          factory method: print an i.IntegerT object.
 Object IRsh(ArrayList sub)
          factory method: right shift two i.IntegerT trees.
 Object ISub(ArrayList sub)
          factory method: subtract two i.IntegerT trees.
 Object IXor(ArrayList sub)
          factory method: bit-xor two i.IntegerT trees.
static void main(String[] args)
          type lines with integer expressions.
protected  PrintStream out()
          returns print action stream.
 Object prefix(String name, List op)
          factory method, based on reflection: create typed operator node of same name.
 Object visit(int _action, Object _object)
          visits an object.
 Object visit(Object object)
          visits an object.
 Object visit0(Object object)
          visits an object, ignoring possible descendants.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

protected transient PrintStream out
print action stream. Can be replaced to reroute output. BUG: should be a self-flushing PrintWriter.


_rules

protected final HashMap _rules
maps class to array of Rule.

Constructor Detail

i

public i()
Method Detail

out

protected PrintStream out()
returns print action stream. Defaults to System.out.


visit

public Object visit(Object object)
             throws Exception
visits an object. This is a facade for the class search.

Specified by:
visit in interface Visitor
Parameters:
object - to be visited, not null.
Returns:
result of action.
Throws:
NoRuleException - if no rule can be found.
Exception
See Also:
Rule.visit(jag.Visitor, java.util.HashMap, java.lang.Object, int, java.util.List)

visit0

public Object visit0(Object object)
              throws Exception
visits an object, ignoring possible descendants. This is a facade for the class search with degree zero.

Specified by:
visit0 in interface Visitor
Parameters:
object - to be visited, not null.
Returns:
result of action.
Throws:
NoRuleException - if no rule can be found.
Exception
See Also:
Rule.visit(jag.Visitor, java.util.HashMap, java.lang.Object, int, java.util.List)

visit

public Object visit(int _action,
                    Object _object)
             throws Exception
visits an object.

Specified by:
visit in interface Visitor
Parameters:
_action - index.
_object - to be visited, not null.
Returns:
result of action.
Throws:
NoRuleException - if no rule can be found.
Exception

IntegerT

public i.IntegerT IntegerT(Integer i)
factory method: type an Integer leaf.


prefix

public Object prefix(String name,
                     List op)
factory method, based on reflection: create typed operator node of same name.

Parameters:
name - to prepend.
op - tree, contains the typed subtrees.

main

public static void main(String[] args)
                 throws Exception
type lines with integer expressions.

Throws:
Exception

classname

public static String classname(Object o)
returns simplified classname.


IPrint

public Object IPrint(i.IntegerT sub)
factory method: print an i.IntegerT object.


IOr

public Object IOr(ArrayList sub)
factory method: bit-or two i.IntegerT trees.


IXor

public Object IXor(ArrayList sub)
factory method: bit-xor two i.IntegerT trees.


IAnd

public Object IAnd(ArrayList sub)
factory method: bit-and two i.IntegerT trees.


ILsh

public Object ILsh(ArrayList sub)
factory method: left shift two i.IntegerT trees.


IRsh

public Object IRsh(ArrayList sub)
factory method: right shift two i.IntegerT trees.


IAdd

public Object IAdd(ArrayList sub)
factory method: add two i.IntegerT trees.


ISub

public Object ISub(ArrayList sub)
factory method: subtract two i.IntegerT trees.


IMul

public Object IMul(ArrayList sub)
factory method: multiply two i.IntegerT trees.


IDiv

public Object IDiv(ArrayList sub)
factory method: divide two i.IntegerT trees.


IMod

public Object IMod(ArrayList sub)
factory method: remainder of two i.IntegerT trees.


IMinus

public Object IMinus(ArrayList sub)
factory method: sign-change an i.IntegerT tree.


INeg

public Object INeg(ArrayList sub)
factory method: bit-complement an i.IntegerT tree.