prolog-dcg

Parse and generate text bidirectionally with Prolog Definite Clause Grammars.

1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/hafley66/claude-research --skill prolog-dcg
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: prolog-dcg
Source: https://github.com/hafley66/claude-research/tree/main/skills/prolog-dcg
Command: npx skills add https://github.com/hafley66/claude-research --skill prolog-dcg

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Prolog DCGs provide a concise way to define grammars and parsers by embedding list threading directly into Prolog rules, enabling parsing and generation from a single, bidirectional specification.

Core Features & Use Cases

  • DCG syntax and transformation to standard clauses for terminals and nonterminals.
  • phrase/2 and phrase/3 interfaces for parsing, recognition, and generation.
  • Bidirectional grammars that support both parsing and generation with Prolog backtracking.
  • Optional state threading and pushback to handle complex parsing tasks.
  • Use Case: quickly prototype a small language grammar and generate sample sentences.

Quick Start

Define a small DCG rule and use phrase/2 to parse a sample input.

Frequently Asked Questions about prolog-dcg

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Prolog DCGs for parsing and generation?

Prolog DCGs handle parsing and generation by embedding list threading into rules, allowing a single grammar specification to parse input or generate output using backtracking. You define terminals and nonterminals, then query them through phrase/2 or phrase/3.

What is the difference between phrase/2 and phrase/3 in Prolog grammars?

In Prolog grammars, phrase/2 is used to parse or generate a list against a nonterminal, while phrase/3 includes an additional argument for threading hidden state, enabling complex parsing tasks like pushback and stateful transformations.

Can I build a language recognizer with Prolog DCGs?

Yes, you can build small language recognizers with Prolog DCGs. By defining grammar rules that transform input through hidden arguments, the grammar acts as a bidirectional recognizer and generator, validating if an input list matches the specified structure.

How do terminals and nonterminals transform input in Definite Clause Grammars?

In Definite Clause Grammars, terminals and nonterminals transform input by automatically threading list arguments through standard clauses. Terminals consume elements from the input list, while nonterminals call sub-rules, allowing the grammar to sequentially process and match the input string.

Do I need prior Prolog knowledge to use Definite Clause Grammars?

Yes, using Definite Clause Grammars requires understanding of Prolog backtracking, DCG rules, and how hidden arguments transform input. It is designed for developers already working within Prolog projects who need to quickly prototype small language grammars.

What is the best way to generate sample sentences from a grammar in Prolog?

The best way to generate sample sentences in Prolog is defining a bidirectional DCG grammar and using phrase/2. Prolog's backtracking will enumerate valid sentence structures that match your grammar rules, serving as a built-in sentence generator.