// strategy S1 = to Vertex . strategy S = { Cd_graph -> Alternat Alternat -> Vertex } . Cd_graph { traversal allInh(CountingVisitor c) { { Cd_graph -> Alternat Alternat -> Vertex }; // to Vertex; // is incorrect; should be: // *from* Cd_graph *via* Alternat *to* Vertex } // traversal method/visitor names // want to reuse traversal method and counting visitor int countInhRels2() = allInh(CountingVisitor); // strategy/visitor names int countInhRels4() to Vertex (CountingVisitor,DisplayVisitor); // strategy/visitor names // int countInhRels6() do S (CountingVisitor); // traversal method/inlined visitor int countInhRels3() = allInh { (@ int total; @) init (@ total = 0; @) before Vertex (@ total = total +1; @) after {Cd_graph,Adj} (@ System.out.println("CountingVisitor is leaving " +host.getClass().toString() + " total = " + total); @) return int (@ total @) } // strategy/inlined visitor int countInhRels5() to Vertex { (@ int total; @) init (@ total = 0; @) before Vertex (@ total = total +1; @) after {Cd_graph,Adj} (@ System.out.println("CountingVisitor is leaving " +host.getClass().toString() + " total = " + total); @) return int (@ total @) } // verbatim method = Java method (@ int countInhRels() { CountingVisitor count = new CountingVisitor(); this.allInh(count); return count.get_return_val(); } @) } CountingVisitor { init (@ total = 0; @) before Vertex (@ total = total +1; @) after {Cd_graph,Adj} (@ System.out.println("CountingVisitor is leaving " +host.getClass().toString() + " total = " + total); @) return int (@ total @) } Main { (@ static public void main(String args[]) throws Exception { Cd_graph graph = Cd_graph.parse(System.in); System.out.println("result = " + graph.countInhRels() + " , " + graph.countInhRels2() + " , " + graph.countInhRels4() + " , " + graph.countInhRels5() + " , " + graph.countInhRels3()); } @) }