Re: term_expansion/2 with DCG clauses
Wouter Beek <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <CAE1un7P4P-=g-LLTYffR0eCWaZLpheO723mgN8t6embFVauqTg@mail.gmail.com> |
Hi Feliks,
My specific use case is that I want to generate DCGs based on ABNF (a
variant of BNF). Most RFC standards define their syntax in ABNF and
having them converted into DCGs seems convenient.
Here is my use of term_expansion/2. The conversion from ABNF to DCGs
is done in rule//1.
~~~{.pl}
system:term_expansion(ABNF, DCGs):-
ABNF =.. [:-,abnf(Atom),_],
atom_codes(Atom, Codes),
once(phrase(rule(DCGs), Codes)),
abnf('repeat = 1*DIGIT / (*DIGIT "*" *DIGIT)'):- true.
~~~
---
Cheers!,
Wouter.
E-mail: [email protected]
WWW: www.wouterbeek.com
Tel.: 0647674624
On Tue, Aug 13, 2013 at 3:15 PM, Feliks Kluzniak
<[email protected]> wrote:
> Hi,
>
> I find your question hard to understand. Could you please give an example of what it is that you are after?
>
> Thanks,
> -- Feliks
>
> On Aug 13, 2013, at 14:02, Wouter Beek <[email protected]> wrote:
>
>> Hi all,
>>
>> What would be the recommended way for replacing regular Prolog
>> predicates with DCG rules? I would be nice if I could use the
>> syntactic sugar / `-->`-notation in formulating the replacing rules.
>>
>> I was thinking of using term_expansion/2, but `ResultTerm =..
>> [-->,Head,Body]` would not be correct since `-->` is not the name of
>> the predicate.
>>
>> ---
>> Cheers!,
>> Wouter.
>>
>> E-mail: [email protected]
>> WWW: www.wouterbeek.com
>> Tel.: 0647674624
>> _______________________________________________
>> SWI-Prolog mailing list
>> [email protected]
>> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
>