We covered topics from Prof. Wand's lecture notes (lecture01.pdf) and in addition: We introduced a simple programming language for boolean expressions: import edu.neu.ccs.demeter.dj.*; import java.util.List; Program = PList(Expression) EOF. Expression : LetExp | CNF. LetExp = "let" Literal "in" Expression. CNF = "cnf" PList(Clause). Clause : LitClause | SatClause. LitClause = PList(Literal). SatClause = "sat". Literal : Pos | Neg common Variable. Pos = . Neg = "!". Variable = Ident. PList(S) ~ "(" {S} ")". Main = . We discussed a sample input like this one first: ( let a in let !b in cnf ( (a !b) (!a b)) let !b in cnf ( (b) sat) cnf ( () sat) ) The we introduced a Grammar for s-expressions: import edu.neu.ccs.demeter.dj.*; import java.util.*; Program = SList. SList = List(SExp). SExp : Variable | SList. Variable = Ident. List(S) ~ "(" {S} ")". Main = . and how to flatten them without "follow the grammar": Main { public static void main(String args[]) throws Exception {{ Program p = Program.parse(System.in); p.display(); System.out.println(); ClassGraph cg = new ClassGraph(true, false); List res = p.flatten(cg); System.out.println("flattened list " + res); System.out.println("done"); System.out.println(); }} } Program { void display() to SList (DisplayVisitor); } Program { {{ List flatten(ClassGraph cg){ return cg.gather(this, "from Program to edu.neu.ccs.demeter.Ident"); } }} } We observed that the above flatten function also works for objects of the first grammar. In order to fix a grammar notation, we introduced a grammar for grammars such as this one: Grammar ~ {Statement}. Statement = NonTerminal "=" Expression ".". Expression ~ Term {"|" Term}. Term ~ Factor {Factor}. Factor : NonTerminal | Terminal | Compound | Bracketed | Curlyed. Compound = "(" Expression ")". Bracketed = "[" Expression "]". Curlyed = "{" Expression "}". NonTerminal = Ident. Terminal = String. We actually used a greatly simplified form of: http://www.ccs.neu.edu/research/demeter/DemeterJava/use/generate.cd (focus on the class definitions).