Article View: comp.lang.prolog
Article #999Re: Prolog's Pitfalls?
From: Richard A. O'Keefe
Date: Fri, 20 Jul 1990 09:37
Date: Fri, 20 Jul 1990 09:37
27 lines
1388 bytes
1388 bytes
In article <31467@cup.portal.com>, pgl@cup.portal.com (Peter G Ludemann) writes:
> There's another technique, which no-one seems to have mentioned:
> meta-grammar rules. What you want here is a sequence of "prim"s:
>
> expr(E) --> seq(prim,E) .
>
> No problem: just define a meta-rule:
>
> seq(X,[E1|E2]) --> X(E1), seq(X,E2) .
> seq(X,[]) --> [] .
>
In current Quintus Prolog, use 'phrase':
seq(X, [E1|E2]) --> {augment_term(X1, X, E1)}, phrase(X1),
seq(X, E2).
seq(X, []) --> [].
I'll add phrase/N for N > 3 (i.e. phrase//M for M > 1) to the library
so that you'll be able to write
seq(X, [E1|E2]) --> phrase(X, E1), seq(X, E2).
Generally speaking, where you would have used call/N in ordinary code
you would use phrase//N in a grammar rule.
--
Science is all about asking the right questions. | ok@goanna.cs.rmit.oz.au
I'm afraid you just asked one of the wrong ones. | (quote from Playfair)
Technical Details
Message-ID:
<3449@goanna.cs.rmit.oz.au>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!samsung!munnari.oz.au!goanna!okReferences:
<1990Jun18.221058.11331@chaos.cs.brandeis.edu> <31467@cup.portal.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: Prolog's Pitfalls? Message-ID: <3449@goanna.cs.rmit.oz.au> Date: 20 Jul 90 09:37:15 GMT References: <1990Jun18.221058.11331@chaos.cs.brandeis.edu> <31467@cup.portal.com> Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 27