# \#dcg

**URL:** https://swi-prolog.discourse.group/tag/dcg/87.md

[Latest](https://swi-prolog.discourse.group/latest.md) · [Categories](https://swi-prolog.discourse.group/categories.md) · [Tags](https://swi-prolog.discourse.group/tags.md)

---

## [Why are empty productions of DCG grammars translated so that unifications occur in the body?](https://swi-prolog.discourse.group/t/why-are-empty-productions-of-dcg-grammars-translated-so-that-unifications-occur-in-the-body/9409)

<div class="topic-metadata">

**Author:** [@neuroevolutus](https://swi-prolog.discourse.group/u/neuroevolutus)\
**Replies:** 2\
**Last updated:** [December 2, 2025, 8:48am UTC](https://swi-prolog.discourse.group/t/why-are-empty-productions-of-dcg-grammars-translated-so-that-unifications-occur-in-the-body/9409 "2025-12-02T08:48:16Z")

</div>

I’ve been trying to learn more about DCGs, and, while looking at the blanks predicate from the library dcg/basics, I noticed that what corresponds to the DCG rule blanks --\> \[\]. is translated into blanks(A, B) :- A=B.. M…

---

## [Double\_quotes flag and DCGs](https://swi-prolog.discourse.group/t/double-quotes-flag-and-dcgs/6730)

<div class="topic-metadata">

**Author:** [@mvolkmann](https://swi-prolog.discourse.group/u/mvolkmann)\
**Replies:** 12\
**Last updated:** [June 30, 2025, 2:18pm UTC](https://swi-prolog.discourse.group/t/double-quotes-flag-and-dcgs/6730 "2025-06-30T14:18:45Z")

</div>

Through trial and error I’ve arrived at the opinion that setting the double\_quotes flag to chars is a bad idea when working with DCGs. It seems to break the functionality of the predicates defined in the dcg/basics libra…

---

## [Preventing Backtracking with DCGs](https://swi-prolog.discourse.group/t/preventing-backtracking-with-dcgs/7426)

<div class="topic-metadata">

**Author:** [@JosephOziel](https://swi-prolog.discourse.group/u/JosephOziel)\
**Replies:** 8\
**Last updated:** [May 2, 2024, 1:13am UTC](https://swi-prolog.discourse.group/t/preventing-backtracking-with-dcgs/7426 "2024-05-02T01:13:55Z")

</div>

I have this dcg code: program(\[Node|Rest\]) --\> item(Node), (program(Rest) | {Rest = \[\]}). item(Node) --\> lit(Node) | quote(Node) | pat\_obj(Node) | word(Node). %| word\_def(Node). lit(num(N, L)) --\> \[lit(N, L)\], {number…

---

## [Blog post on graphical grammar 2: Epsilon](https://swi-prolog.discourse.group/t/blog-post-on-graphical-grammar-2-epsilon/7373)

<div class="topic-metadata">

**Author:** [@kwon-young](https://swi-prolog.discourse.group/u/kwon-young)\
**Replies:** 0\
**Last updated:** [April 14, 2024, 6:21pm UTC](https://swi-prolog.discourse.group/t/blog-post-on-graphical-grammar-2-epsilon/7373 "2024-04-14T18:21:33Z")

</div>

Hello, Here is my second blog post on using graphical grammar together with a configurable upper bound error which I call Epsilon. In the post, I try to explain the problem of comparing reals and use epsilon to measure…

---

## [Initial attempt at a kif to Prolog translator](https://swi-prolog.discourse.group/t/initial-attempt-at-a-kif-to-prolog-translator/6771)

<div class="topic-metadata">

**Author:** [@joeblog](https://swi-prolog.discourse.group/u/joeblog)\
**Replies:** 9\
**Last updated:** [August 21, 2023, 1:06pm UTC](https://swi-prolog.discourse.group/t/initial-attempt-at-a-kif-to-prolog-translator/6771 "2023-08-21T13:06:57Z")

</div>

Edit I’ve changed \[60,61\] to “\<=” and similarly other codes I was using to strings thanks to @jan pointing out that works. After a bit of a hiatus, I’ve started tinkering around with automating the conversion of some of…

---

## [Dcg/high\_order sequence/3 nested with the same separator](https://swi-prolog.discourse.group/t/dcg-high-order-sequence-3-nested-with-the-same-separator/5990)

<div class="topic-metadata">

**Author:** [@dklyons81](https://swi-prolog.discourse.group/u/dklyons81)\
**Replies:** 3\
**Last updated:** [December 4, 2022, 9:06pm UTC](https://swi-prolog.discourse.group/t/dcg-high-order-sequence-3-nested-with-the-same-separator/5990 "2022-12-04T21:06:26Z")

</div>

Hi, I’m trying to parse the Advent of Code 2022 Day 1 input file, which looks like this: 1000 2000 3000 4000 5000 6000 7000 8000 9000 10000 For the purposes of this challenge, this should parse to \[\[1000,2000,3000…

---

## [Tokenizing files with DCGs](https://swi-prolog.discourse.group/t/tokenizing-files-with-dcgs/5679)

<div class="topic-metadata">

**Author:** [@natarg](https://swi-prolog.discourse.group/u/natarg)\
**Replies:** 3\
**Last updated:** [August 12, 2022, 12:16pm UTC](https://swi-prolog.discourse.group/t/tokenizing-files-with-dcgs/5679 "2022-08-12T12:16:12Z")

</div>

I am trying to write a tokenizer with DCGs (I am a newbie) using this as a template. My file format so far allows for strings, numbers and parenthesis, and I’d like to add comments. Example: ;;;;;;;;;;;;;;;;;;;;;;;;;;;…

---

## [Deterministically parsing with library(dcg/high\_order)](https://swi-prolog.discourse.group/t/deterministically-parsing-with-library-dcg-high-order/5292)

<div class="topic-metadata">

**Author:** [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Replies:** 14\
**Last updated:** [April 18, 2022, 4:47pm UTC](https://swi-prolog.discourse.group/t/deterministically-parsing-with-library-dcg-high-order/5292 "2022-04-18T16:47:24Z")

</div>

My question boils down to: if we do have sequence//2 (and also sequence//3 and sequence//5), how can we get the corresponding det\_sequence//2? The naive implementation for the 2-argument version: det\_sequence(G, \[H|T\]) …

---

## [DCGs with single-sided unification?](https://swi-prolog.discourse.group/t/dcgs-with-single-sided-unification/3768)

<div class="topic-metadata">

**Author:** [@peter.ludemann](https://swi-prolog.discourse.group/u/peter.ludemann)\
**Replies:** 16\
**Last updated:** [January 19, 2022, 3:38pm UTC](https://swi-prolog.discourse.group/t/dcgs-with-single-sided-unification/3768 "2022-01-19T15:38:10Z")

</div>

I’ve made an experimental implementation of extended DCGs (edcg pack) that generates clauses with single-sided unification (=\>) instead of full unification (:-). (You can see the changes here). I propose using the oper…

---

## [Different behavior when exporting a tabled predicate](https://swi-prolog.discourse.group/t/different-behavior-when-exporting-a-tabled-predicate/4799)

<div class="topic-metadata">

**Author:** [@brunokim](https://swi-prolog.discourse.group/u/brunokim)\
**Replies:** 6\
**Last updated:** [December 23, 2021, 7:35pm UTC](https://swi-prolog.discourse.group/t/different-behavior-when-exporting-a-tabled-predicate/4799 "2021-12-23T19:35:33Z")

</div>

I’m using: SWI-Prolog version 8.4.1 I’m writing a parser with DCGs that exhibits weird behavior, which I’m inclined to believe is a bug on tabling and/or compilation. I can reliably turn the bug on or off by exporting t…

---

## [Problem with number//1](https://swi-prolog.discourse.group/t/problem-with-number-1/4162)

<div class="topic-metadata">

**Author:** [@hnbeck](https://swi-prolog.discourse.group/u/hnbeck)\
**Replies:** 12\
**Last updated:** [July 15, 2021, 2:02pm UTC](https://swi-prolog.discourse.group/t/problem-with-number-1/4162 "2021-07-15T14:02:09Z")

</div>

Hello, I’m using: SWI-Prolog version 8.2.4 on Win10 I want to parse a sequence of numbers (floats and integers) and words (some are keywords, some just identifiers), separated by whitespace, like " -4 2.1 add" I use t…
