Generate code by parsing the diagram in spatial order

(Adding elements in a sorted array)