(C1) The output should contain only those NxN patterns of pixels that are present in the input. (Weak C2) Distribution of NxN patterns in the input should be similar to the distribution of NxN ...
With DelphiAST you can take real Delphi code and get an abstract syntax tree. One unit at time and without a symbol table though. FreePascal and Lazarus compatible.