[m-dev.] Fw: Replacement syntax for DCGs

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 29 21:50:53 AEDT 2001


On 26-Nov-2001, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> Here's yet another DCG-replacement suggestion.
...
> we would make ! an infix binary operator and write
> 
> io ! foo :-
> 	p(...),
> 	q(...),
> 	io ! io__print(...),
> 	r(...),
> 	io ! io__print(...).

One nice thing about DCGs, IMHO, is that they have a declarative
semantics as well as a translation semantics.  I think EDCGs also have
that property.  But your proposal doesn't.

Actually that is a small lie; in their current form, where a
predicate can be defined using DCG notation and then called directly
from non-DCG code by just passing the extra arguments, Mercury's DCGs
don't have a declarative semantics.  But if we required that non-DCG
code only call DCG code via phrase/3, then they would have a declarative
semantics.

The declarative semantics for DCGs can be given by treating DCG rules as
ordinary clauses for '-->'/2 and treating phrase/3 as a meta-interpreter:

	phrase(X, S0, S) :-
		(X --> Y),
		phrase(Y, S0, S).
	phrase((A,B), S0, S) :-
		phrase(A, S0, S1),
		phrase(B, S1, SS).
	phrase((if A then B else C), S0, S) :-
		(if phrase(A, S0, S1) then phrase(B, S1, S)
		else phrase(C, S0, S)).
	phrase({G}, S, S) :-
		call(G).
	phrase(=(S), S, S).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list