Re: term_expansion/2 with DCG clauses
Kilián Imre <[email protected]>
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Organization | Gyűrűfű |
| Message-ID | <[email protected]> |
Hi! To write a DCG **interpreter** instead of the term_expansion/2 compiler is a finger-easy students' job (cca. 10 lines of code). If you want to extend it (DCG--ABNF or anything else) - and if the definition is clear - then to write the appropriate interpreter is only a little bit more complicated. yours: imre On Tue, 13 Aug 2013 15:49:43 +0200 Wouter Beek <[email protected]> wrote: > 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 > > > > > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog -- Kilián Imre <[email protected]>