The append's are expensive -- Prolog uses difference lists instead.
The rule
s(A,B) :- np(A,C), vp(C,B).
says that there is a sentence at the beginning of A (with B left over) if
there is a noun phrase at the beginning of A (with C left over), and
there is a verb phrase at the beginning of C (with B left over).
DCGs can build parse trees which can be used to
construct a semantic interpretation of the sentence.
The tree is built bottom-up, when Prolog returns from
recursive calls. We give each phrase structure rule an
extra argument which represents the node to be
constructed.
A grammar rule is written LHS -> RHS.
The left-hand side (LSH) must be a non-terminal
symbol, the right-hand side (RHS)
can be a combination of terminals, non-terminals, and
Prolog goals.
Terminal symbols (words) are in square brackets:
n -> [house].
More than one terminal can be matched by
one rule: np -> [the,house].