import edu.neu.ccs.demeter.dj.*; import java.util.*; EquationSystem = List(Equation). List(S) ~ "(" {S} ")". Equation = Variable "=" Expression. Expression : Simple | Compound. Simple : Variable | Numerical. Variable = Ident. Numerical = int. Compound = Op List(Expression). Op : Add. Add = "+". Main = . ===================================================================== // program.prj -- Demeter/Java project file (version 0.8.3) // 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 = program.cd // The behavior files. BEHFILES = program.beh mitch.beh print.beh // The cool files. COOLFILES = // The ridl files. RIDLFILES = // 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 = javac // Java compiler arguments. COMPILE_ARGS = -g -deprecation // Java classpath to be passed to the COMPILER. Whatever you // put here comes after CLASSDIR:GENDIR, but before $CLASSPATH. CLASSPATH = // 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 = program.input // Files and directories to be removed when cleaning up. CLEAN_ARGS = gen ===================================================================== Main { {{ public static void main(String args[]) throws Exception { EquationSystem s = EquationSystem.parse(System.in); System.out.println("done parsing"); // ClassGraph cg = new ClassGraph(true, false); HashSet used = s.getUsedVars(); Iterator it = used.iterator(); System.out.println(" Used Variables"); while (it.hasNext()){ Variable curvar = (Variable) it.next(); System.out.println(); curvar.print(); } System.out.println(); HashSet defined = s.getDefinedVars(); System.out.println("done"); } }} } EquationSystem { {{ static ClassGraph cg = new ClassGraph(true, false); static String usedVarsSpec = "from EquationSystem via -> *,rhs,* to Variable"; static String definedVarsSpec = "from EquationSystem via -> *,lhs,* to Variable"; HashSet collectVars(String travspec){ Visitor v = new Visitor(){ HashSet return_val = new HashSet(); void before(Variable v1) {return_val.add(v1);} public Object getReturnValue(){return return_val;} }; return (HashSet) cg.traverse(this, travspec, v); } HashSet getUsedVars() { return this.collectVars(usedVarsSpec); } HashSet getDefinedVars() { return this.collectVars(definedVarsSpec); } }} } Variable { void print() to * (PrintVisitor); } ===================================================================== ( a = + (3 4 5) b = + (c d) d = 6 ) ===================================================================== Reading project file program.prj... Running the test... done parsing Used Variables c d done