From ok@atlas.otago.ac.nz Wed Oct 17 02:18:44 2001
Received: from atlas.otago.ac.nz (atlas.otago.ac.nz [139.80.32.250])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f9H0Iht02206
	for <prolog@swi.psy.uva.nl>; Wed, 17 Oct 2001 02:18:43 +0200 (MET DST)
Received: (from ok@localhost)
	by atlas.otago.ac.nz (8.9.3/8.9.3) id NAA85096;
	Wed, 17 Oct 2001 13:18:22 +1300 (NZDT)
Date: Wed, 17 Oct 2001 13:18:22 +1300 (NZDT)
From: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>
Message-Id: <200110170018.NAA85096@atlas.otago.ac.nz>
To: dichevc@wssu.edu, prolog@swi.psy.uva.nl
Subject: Re:  [SWIPL] SWI-Prolog - Definite Clause Grammar

"Dichev, Christo" <dichevc@wssu.edu> wrote:
	Maybe "phrase/2" or "phrase/3" are provided for that purpose,
	but I don't know how to use them.

phrase/[2,3] are to DCGs are call/1 is to normal predicates.

phrase(Form, Sequence) :-
    'expand as if it were a DCG body'(Form, S0, S, Expansion),
    S0 = Sequence, S = [],
    call(Expansion).

phrase(Form, Seq0, Seq) :-
    'expand as if it were a DCG body'(Form, S0, S, Expansion),
    S0 = Seq0, S = Seq,
    call(Expansion).

The purpose of phrase/2 is to be an interface between DCG rules and
normal clauses.  For example,

    solve :-
        read_sentence(Problem),
        phrase(sentence(Interpretation), Problem, []),
        solve_interpretation(Interpretation).

    sentence(Interpretation) --> ....

The purpose of phrase/3 is to provide an analogue of call/1 that
may be used in the body of a grammar rule.

For example,

    :- op(10, xf, *).

    X* --> [] ; X, X*.

Some DCG expanders will handle this, some will not.
The ones that do handle it should handle it as if it read

    X* --> [] ; phrase(X), X*.

How do I know that?  Because that's what I invented phrase/3 for.

	Is it possible to express in SWI-Prolog grammar rules in the form:
	
		s --> [a], [b].
		s --> [a], s, [b].
	
Yes.

