{"id":17774942,"url":"https://github.com/fnogatz/dcg4pt","last_synced_at":"2026-02-16T09:33:56.975Z","repository":{"id":47396795,"uuid":"154346054","full_name":"fnogatz/dcg4pt","owner":"fnogatz","description":"Extend Definite Clause Grammars for Prolog by the corresponding parse tree","archived":false,"fork":false,"pushed_at":"2023-01-20T11:03:38.000Z","size":36,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-24T11:02:23.914Z","etag":null,"topics":["definite-clause-grammar","grammar","parsing","prolog"],"latest_commit_sha":null,"homepage":"","language":"Prolog","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fnogatz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-23T14:48:55.000Z","updated_at":"2025-08-12T18:48:15.000Z","dependencies_parsed_at":"2023-02-12T01:30:39.671Z","dependency_job_id":null,"html_url":"https://github.com/fnogatz/dcg4pt","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/fnogatz/dcg4pt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnogatz%2Fdcg4pt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnogatz%2Fdcg4pt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnogatz%2Fdcg4pt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnogatz%2Fdcg4pt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnogatz","download_url":"https://codeload.github.com/fnogatz/dcg4pt/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnogatz%2Fdcg4pt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29504764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["definite-clause-grammar","grammar","parsing","prolog"],"created_at":"2024-10-26T21:54:13.489Z","updated_at":"2026-02-16T09:33:56.926Z","avatar_url":"https://github.com/fnogatz.png","language":"Prolog","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DCGs for Parse Trees\n\nExtend Definite Clause Grammars (DCG) for Prolog by an additional argument to automatically store the parse tree.\n\n## Synopsis\n\n```prolog\n:- use_module(library(dcg4pt/expand)).\n\n% Extended DCGs get expanded to hold an additional\n%   argument with parse tree.\nsentence --\u003e noun_phrase(N), verb_phrase(N).\nnoun_phrase(N) --\u003e determiner, noun(N).\nverb_phrase(N) --\u003e ( verb(N) ; verb(N), noun_phrase(_) ).\nnoun(sg) --\u003e [boy]  ; [apple].\nnoun(pl) --\u003e [boys] ; [apples].\ndeterminer --\u003e [the].\nverb(sg) --\u003e [eats].\nverb(pl) --\u003e [eat].\n\nmain :-\n  phrase(sentence(Tree), [the, boy, eats, the, apples]),\n  print_term(Tree, [indent_arguments(2)]).\n\n% prints:\n%   sentence([\n%     noun_phrase([\n%       determiner(the),\n%       noun(boy) ]),\n%     verb_phrase([\n%       verb(eats),\n%       noun_phrase([\n%         determiner(the),\n%         noun(apples) ]) ]) ])\n```\n\n## Installation\n\nThis pack is available from the [add-on registry of SWI-Prolog](http://www.swi-prolog.org/pack/list).\n\nIt can be installed with `pack_install/1`:\n\n```prolog\n?- pack_install(dcg4pt).\n```\n\n## Requirements\n\nOnly for development purposes the [`tap` pack](http://www.swi-prolog.org/pack/list?p=tap) is needed:\n\n```prolog\n?- pack_install(tap).\n```\n\n## DCG Expansion\n\nIn most cases you simply want to automatically expand all given DCGs with the additional parse tree argument. To do so, simply call:\n\n```prolog\n:- use_module(library(dcg4pt/expand)).\n% and later the definition of DCGs\n```\n\nAdditionally you can manually call the predicates to translate a DCG4PT rule:\n\n```prolog\n?- use_module(library(dcg4pt)).\n?- dcg4pt_rule_to_dcg_rule((sentence --\u003e noun_phrase, verb_phrase), DCG).\nDCG = (sentence(X) --\u003e ( ... )).\n```\n\n## Usage\n\nYou can use the generated predicates like normal DCGs, besides that they provide an additional argument to hold the parse tree. It is automatically added as the very last argument of the DCG body.\n\n### Bound Arguments\n\n`library(dcg4pt)` has been implemented to provide a tool that generates a parse tree from a given input list but also the other way around, i.e., to generate a list based on a parse tree. So you can also use it this way:\n\n```prolog\n?- Tree = noun_phrase([determiner(the), noun(boy)]),\n   phrase(noun_phrase(N, Tree), List).\nTree = noun_phrase([determiner(the), noun(boy)]),\nN = sg,\nList = [the, boy] .\n```\n\n### Sequences\n\n`library(dcg4pt)` provides a built-in `sequence(+Quantifier, :Body)` DCG body to resolve sequences of `Body` with the quantifiers `'?'`, `'+'`, and `'*'` as known from regular expressions. Their occurrences are represented as (possibly empty) lists in the parse tree:\n\n```prolog\n:- use_module(library(dcg4pt/expand)).\n\nsingle --\u003e [a].\nlist --\u003e sequence('*', single).\nnon_empty_list --\u003e sequence('+', single).\noptional --\u003e sequence('?', single).\n\nmain :-\n  phrase(list(Tree), [a, a, a]),\n  print_term(Tree, [indent_arguments(2)]).\n\n% prints:\n%   list([\n%     single(a),\n%     single(a),\n%     single(a) ])\n```\n\nWith a free variable given as the parse tree, the possibilities are generated beginning with the smallest solution:\n\n```prolog\n?- phrase(non_empty_list(Tree), List).\nTree = non_empty_list([single(a)]),\nList = [a] ;\nTree = non_empty_list([single(a), single(a)]),\nList = [a, a] ;\n...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnogatz%2Fdcg4pt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnogatz%2Fdcg4pt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnogatz%2Fdcg4pt/lists"}