// class dictionary Cd_graph = Adj Adj_list. Adj = Vertex Neighbors ".". Neighbors: Construct | Alternat. Construct = "=" Any_vertex_list. Alternat = ":" Vertex "|" Vertex. Any_vertex : Labeled_vertex | Syntax_vertex. Syntax_vertex = String. Labeled_vertex = "<" Ident ">" Vertex. Adj_list: Cd_graph | Empty_cd_graph . Any_vertex_list: Nany_vertex_list | Empty. Nany_vertex_list = Any_vertex Any_vertex_list. Empty = . Empty_cd_graph = . Vertex = Ident. /////////////// visitor CountingVisitor = int. endvisitors /////////////// Main = . Cd_graph { traversal allInh(CountingVisitor c) { to Vertex; // is incorrect; should be: // from Cd_graph via ? to Vertex } int countInhRels2() = allInh(CountingVisitor); 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()); } }} } // program.prj -- Demeter/Java project file // NOTE: This file may contain path names or other platform-dependent // information. You may need to edit them when moving from one // platform to another. // The class dictionary file. CDFILE = class-graph.cd // The behavior files. BEHFILES = class-graph.beh // The name of the class which has the "main" method. MAIN = Main // The package your generated code belongs to. It should match // the package specified at the beginning of your .cd file. PACKAGE = // Code generator arguments. GENERATE_ARGS = -tracevis -displayvis -printvis -copyvis -equalvis // The directory into which .java files are generated. GENDIR = gen // The parser generator executable. PARSEGEN = javacc // Parser generator arguments. PARSEGEN_ARGS = // The Java compiler executable. COMPILER = jikes // Java compiler arguments. COMPILE_ARGS = -g -depend +E // The directory into which .class files are generated. CLASSDIR = gen/classes // The Java virtual machine executable. JVM = java // The virtual machine option for setting the class path. CLASSPATH_OPTION = -classpath // Arguments for testing the program. TEST_ARGS = // Input file for testing the program. TEST_INPUT = class-graph.input // Files and directories to be removed when cleaning up. CLEAN_ARGS = gen // class dictionary Cd_graph = Adj Adj_list. Adj = Vertex Neighbors ".". Neighbors: Construct | Alternat. Construct = "=" Any_vertex_list. Alternat = ":" Vertex "|" Vertex. Any_vertex : Labeled_vertex | Syntax_vertex. Syntax_vertex = String. Labeled_vertex = "<" Ident ">" Vertex. Adj_list: Empty_cd_graph | Cd_graph. Any_vertex_list: Empty | Nany_vertex_list. Nany_vertex_list = Any_vertex Any_vertex_list. Empty = . Empty_cd_graph = . Vertex = Ident. CountingVisitor = Integer. Main = .