4

in this site, I found a part that explains how to build Right-hand Context Notation using DCG

A → ε | a A

Head, [T_1,...,T_n] --> Body.

someone help me figure out this method by example and illustrate its benefits to parse context-free grammar

false
  • 10,264
  • 13
  • 101
  • 209
Ans Piter
  • 573
  • 1
  • 5
  • 17

2 Answers2

3

This notation is called a semicontext. See, e.g. this answer. With it you have strictly more power than context-free grammars. In fact, it is already type 0.

Community
  • 1
  • 1
false
  • 10,264
  • 13
  • 101
  • 209
  • 1
    thnks,I found an interesting article [-ISO/IEC DTR 13211–3:2006](http://www.complang.tuwien.ac.at/ulrich/iso-prolog/dcgs/dcgsdraft-2015-11-10.pdf), and I found the definition of semicontext in chap7.13.3. – Ans Piter Feb 26 '16 at 20:33
  • 1
    @AnsPiter: Right, that's the most recent version. – false Feb 26 '16 at 23:51
3

Look for Semicontext notation at DCG Primer: it's well explained, with examples

CapelliC
  • 59,646
  • 5
  • 47
  • 90
  • thnks, about yr link, `phrase_from_file//` it's not available in sicstus ,is there a (easy) solution ? – Ans Piter Feb 26 '16 at 19:50
  • 2
    In SWI-Prolog, I use [read_file_to_codes](http://www.swi-prolog.org/pldoc/doc_for?object=read_file_to_codes/3), sometime also because phrase_from_file can be difficult to debug... Of course, file should be not huge. – CapelliC Feb 26 '16 at 22:07
  • 2
    Seems it's not available in SICSTUS... but should be easy to implement with read_line (to codes) – CapelliC Feb 26 '16 at 22:13
  • 1
    @CapelliC: Can you give an example where debugging without `phrase_from_file` is less difficult? – false Feb 27 '16 at 14:41
  • 1
    @false: when backtracking, it was almost impossible to me to understand the context. I had string//1 (from library(dcg/basics)) wrongly joined by empty productions, while parsing SQL backups. That was many years ago, not sure if the debugger behaves better now... – CapelliC Feb 27 '16 at 19:15
  • 3
    @AnsPiter: Here is [`pio`](http://www.complang.tuwien.ac.at/ulrich/Prolog-inedit/sicstus/pio.pl) for SICStus - preliminary version. Do use it with `:- set_prolog_flag(double_quotes, chars).` This will help you a lot in debugging, unless you know ASCII codes by heart. – false Feb 27 '16 at 21:55
  • @false thnk you VM, ,now I copy libraray pio into prolog preference or what ? – Ans Piter Feb 28 '16 at 07:58
  • @false thnks, and is it possible to add library ([dcg_basics](http://www.swi-prolog.org/pldoc/doc/swi/library/http/dcg_basics.pl)) in sicstus ? – Ans Piter Feb 29 '16 at 13:20
  • @AnsPiter: That library contains many impure definitions based on `codes` instead of `chars`. I'd rather go without it. – false Feb 29 '16 at 13:23
  • @false where I find .sicstusrc in spider-eclipse – Ans Piter Mar 04 '16 at 07:43
  • @AnsPiter: You need [the manual](https://sicstus.sics.se/sicstus/docs/4.3.2/html/sicstus/too_002dsicstus.html). Not sure how this applies to spider. – false Mar 04 '16 at 10:08
  • @false sorry,where I find .sicstusrc in sisctus, is it path or file or something else ? you can illustrate the steps because I could not succeed to add 'phrase_from_file' – Ans Piter Mar 04 '16 at 13:26
  • @AnsPiter: I put `.sicstusrc` in my home directory under Linux. – false Mar 04 '16 at 13:36
  • @AnsPiter: If you believe that the SPIDER doc is not good enough you can provide them [feedback on their pages](https://sicstus.sics.se/spider/)! – false Mar 04 '16 at 13:37
  • @false: Many thanks for providing the SICStus variant of this library! Could you please clarify the license conditions? Please be so generous as to put this library into the public domain, so that other systems can also freely use this important component. – mat Mar 05 '16 at 05:47
  • I see. Thank you in any case for providing this. – mat Mar 06 '16 at 05:39
  • @AnsPiter: Did you succeed in using `pio`? – false Mar 27 '16 at 22:17
  • @false I could not add this library :( – Ans Piter Mar 28 '16 at 22:22
  • Simply add it as a normal file. And say `:- use_module(pio).` instead. – false Mar 29 '16 at 06:36