First create grammar string representation (simmilar to BNF notation) and then parse string into object structures. You can easy switch between PEG parser and it extended version (much slower but eats any context-free grammar)