DCG notation is just
syntactic sugar for normal definite clauses in Prolog. For example, the previous example could be translated into the following: sentence(A,Z) :- noun_phrase(A,B), verb_phrase(B,Z). noun_phrase(A,Z) :- det(A,B), noun(B,Z). verb_phrase(A,Z) :- verb(A,B), noun_phrase(B,Z). det([the|X], X). det([a|X], X). noun([cat|X], X). noun([bat|X], X). verb([eats|X], X).
Difference lists The arguments to each functor, such as (A,B) and (B,Z) are
difference lists; difference lists are a way of representing a prefix of a list as the difference between its two suffixes (the bigger including the smaller one). Using Prolog's notation for lists, a singleton list prefix P = [H] can be seen as the difference between [H|X] and X, and thus represented with the pair ([H|X],X), for instance. Saying that P is the difference between A and B is the same as saying that append(P,B,A) holds. Or in the case of the previous example, append([H],X,[H|X]). Difference lists are used to represent lists with DCGs for reasons of efficiency. It is much more efficient to concatenate list differences (prefixes), in the circumstances that they can be used, because the concatenation of (A,B) and (B,Z) is just (A,Z). Indeed, append(P,B,A), append(Q,Z,B) entails append(P,Q,S), append(S,Z,A). This is the same as saying that list concatenation is
associative: A = P + B = P + (Q + Z) = (P + Q) + Z = S + Z = A == Non-context-free grammars ==