On 11/17/2012 01:52 AM, Daniel Diaz wrote:
> H,
> 
> Le 17 nov. 2012 à 08:05, Christopher Howard a écrit :
> 
> 
> "generates" does not seem to me the correct verb here. It would be 
> "recognizes" (DCG are mainly done for parsing, even if they can be used to 
> generate strings according to the grammar this is often very limited - as for 
> any Prolog predicate).
> 
> 
> The problem with this grammar is that the number of 'a' and the number of 'd' 
> are not related. Recall context-free grammars are grammars which works "by 
> nesting" (using a stack) (see a more general course on context-free grammars 
> for more information). 
> 
> Here is a grammar that works for your language:
> 
> s --> r.
> s --> [a], s, [d].
> 
> r --> [].
> r --> [b,b], r, [c,c].
> 
> you can check it with:
> 
> | ?- s([a,a,a,b,b,b,b,c,c,c,c,d,d,d], []).
> 
> true
> 
> NB: this grammar will not work well in generation since it will only 
> generates word of the form b^2m c^2m (which are corrects, but no words of 
> other forms can be generated).
> 
> 
> You are right. To include classical Prolog predicate call inside a DCG you 
> have to put it inside curly brackets in the body of the DCG.
> E.g., you could write  s --> as,m,ds,{length(as,X),length(ds,Y),X =:= Y}.
> However, the arguments of length are wrong here (as and ds are Prolog atoms, 
> not lists). You can then extend your DCG non-terminals (e.g., as, ds) with 
> arguments (as(La), ds(Ls)) which can be any Prolog term. You will find online 
> a lot of information on DCG interacting with Prolog code. But this is not 
> needed in this case.
> 
> Daniel
> 
> 
> 

Je vous remercie. That was a very helpful response.

-- 
frigidcode.com

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Users-prolog mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/users-prolog
  • DCGs Christopher Howard
    • Re: DCGs Daniel Diaz
      • Re: DCGs Christopher Howard

Reply via email to