generates all legal sequences based on the given grammar