parse(S,L) :- atom_chars(S,Chars), string(L, Chars, []).

string([X,Y,Z]) --> as(X), bs(Y), {X =< Y}, cs(Z), {Y =< Z}.

as(N) --> [a], as(M), {N is M+1}.
as(0) --> [].

bs(N) --> [b], bs(M), {N is M+1}.
bs(0) --> [].

cs(N) --> [c], cs(M), {N is M+1}.
cs(0) --> [].
