Did you know ... Search Documentation:
Packs (add-ons) for SWI-Prolog

Package "edcgs"

Title:Extended Definite Clause Grammars
Rating:Not rated. Create the first rating!
Latest version:0.1.3
SHA1 sum:f0c3830b7dbc4b27cb8a691eabd0ab356a02739d
Author:Dietmar Seipel <seipel@informatik.uni-wuerzburg.de>
Falco Nogatz <fnogatz@gmail.com>
Maintainer:Falco Nogatz <fnogatz@gmail.com>
Packager:Falco Nogatz <fnogatz@gmail.com>
Home page:https://github.com/fnogatz/edcgs
Download URL:https://github.com/fnogatz/edcgs/releases/*.zip


No reviews. Create the first review!.

Details by download location


Extended DCGs

Extend Definite Clause Grammars (DCG) for Prolog by an additional argument to automatically store the parsing tree.


:- use_module(library(edcgs_expand)).

:- op(1200, xfx, ==>).

% Extended DCGs get expanded to hold additional
%   argument with syntax tree.
sentence ==> noun_phrase, verb_phrase.
noun_phrase ==> determiner, noun.
verb_phrase ==> ( verb ; verb, noun_phrase ).
noun ==> [boy] ; [boys] ; [apple] ; [apples].
determiner ==> [the].
verb ==> [eat].
verb ==> [eats].

main :-
  phrase(sentence(Tree), [the, boy, eats, the, apples]),
  print_term(Tree, [indent_arguments(2)]).

% prints:
%   sentence([
%     noun_phrase([
%       determiner(the),
%       noun(boy) ]),
%     verb_phrase([
%       verb(eats),
%       noun_phrase([
%         determiner(the),
%         noun(apples) ]) ]) ])


This pack is available from the add-on registry of SWI-Prolog.

It can be installed with pack_install/1:

?- pack_install(edcgs).


Only for development purposes the tap pack is needed:

?- pack_install(tap).


In most cases you simply want to automatically expand all EDCGs to regular DCGs. To do so, simply call:

:- use_module(library(edcgs_expand)).
% and later the definition of EDCGs

Additionally you can manually call the predicates to translate an EDCG rule:

?- use_module(library(edcgs)).
?- edcg_rule_to_dcg_rule((sentence ==> noun_phrase, verb_phrase), DCG).
DCG = (sentence(X) --> ( ... )).

Contents of pack "edcgs"

Pack contains 8 files holding a total of 12.7K bytes.