Giving a list of terms in Tokens, phrase/3 parses it according to the grammar defined in Grammar. As the terms in Tokens are parsed in order, any remaining terms are returned in Remainder. Further acceptable solutions are returned on backtracking.
[eclipse]: [user]. a --> []. a --> [z],a. user compiled 212 bytes in 0.03 seconds yes. [eclipse]: phrase(a,[z,z],[]). yes. [eclipse]: phrase(a,[z,z,z,y],[z,y]). yes. [eclipse]: phrase(a,[z,z,y],R). R = [z, z, y] More? (;) R = [z, y] More? (;) R = [y] More? (;) no (more) solution. [eclipse]: phrase(a,X,[y]). X = [y] More? (;) X = [z, y] More? (;) X = [z, z, y] More? (;) X = [z, z, z, y] More? (;) X = [z, z, z, z, y] More? (;) yes. [eclipse]: Fail: phrase(a, [z, z, y], []). Error: phrase(X, [what, time, is, it], [is, it],R). (Error 4). phrase("a", X,R). (Error 5). phrase(456, X,R). (Error 5).