// To demonstrate how to translate class dictionaries // into object displaying visitors // in /proj/asl/lieber/java/java-envs/j-g-displayAsTree A { (@ void g_displayAsTree() { TreeDisplayVisitor pv = new TreeDisplayVisitor(new Integer(0)); this.t(pv); } @) // it is important that you traverse to all classes whose // objects you want to display. If you forget to traverse to // Y, Y-objects will not display. This is an advantage since // you can control with the traversal specification what // to display. traversal t(TreeDisplayVisitor pv) { to {D,E,Y};} // could use to *; } Main { (@ static public void main(String args[]) throws Exception { A a = A.parse(System.in); a.g_displayAsTree(); System.out.println("done "); } @) } TreeDisplayVisitor{ (@ void spaces() { for (int i=0; i < indent.intValue(); i++ ) {System.out.print(" ");}} @) (@ void incr() { this.set_indent(new Integer(this.get_indent().intValue() + 3));} @) (@ void decr() { this.set_indent(new Integer(this.get_indent().intValue() - 3));} @) // The class dictionary is translated systematically into // a TreeDisplayVisitor. The class definition is printed // for more context when reading the object. // The class definition // A = "a" B X "enda". // is translated into the following two visitor methods before A (@ spaces(); System.out.println(" A( = B X ");incr(); @) after A (@ decr(); spaces(); System.out.println(" ) "); @) // B ~ "(" {C} ")". before B (@ spaces(); System.out.println(" B{ ~ {C} "); incr(); @) after B (@ decr(); spaces(); System.out.println(" } "); @) // X = "x" Y. before X (@ spaces(); System.out.println(" X( = Y"); incr(); @) after X (@ decr(); spaces(); System.out.println(" ) "); @) // Y = . before Y (@ spaces(); System.out.println(" Y( "); incr(); @) after Y (@ decr(); spaces(); System.out.println(" ) "); @) // D = "d" Ident. before D (@ spaces(); System.out.println(" D( = Ident"); incr(); spaces(); System.out.println(" Ident(" + host.get_ident() + ")"); @) after D (@ decr(); spaces(); System.out.println(" ) "); @) // E = "e" Integer. before E (@ spaces(); System.out.println(" E( = Integer"); incr(); spaces(); System.out.println(" Integer(" + host.get_integer().intValue() + ")"); @) after E (@ decr(); spaces(); System.out.println(" ) "); @) }