A tutorial for DCG's in swi-Prolog
These files contain some examples to accompany the tutorial.
A tutorial for DCG's in swi-Prolog
A tutorial for DCG's in swi-Prolog
These files contain some examples to accompany the tutorial.
Niftoid - I'll add a note about this version of 'what the heck this is called' to the DCG tut when I get there.
----- Original Message -----
From: Ulrich Neumerkel [email protected]
To: [email protected]
Cc:
Sent: Monday, August 26, 2013 10:51 AM
Subject: Re: DCG
Dear Anne!
Back from the WG17 meeting, the name for the terminal
symbols on the left-hand side of a grammar rule were
again discussed.
right-hand context seems to lead to a lot of misunderstandings
for linguists: A grammar rule is commonly presented as
having a right-hand side RHS and a left-hand side LHS:
LHS --> RHS.
Now, the right-hand context appears in the left-hand side
of the grammar rule.
This leads to a bit too much left-right issues.
Therefore, semicontext was agreed upon. It shares with
the previous notion the same non-operational connotation,
it is much shorter, and yet a blank slate.
It is semi, because a real context (in formal languages)
occurs on both sides:
a, "c" --> b, "c".
Here, the letter c is the context. But if it does not
appear in the body, it is not a context. Thus, a
semicontext.
So, maybe you want to use it.
Best regards,
Ulrich
Dear Anne,
While refreshing my knowledge of DCGs, I stumbled on the double quoted strings,
which - at least now and on a mac - (Multi-threaded, 64 bits, Version 7.2.3)
are not by default a list of character codes. Probably this complicated chapter
is relevant here: http://www.swi-prolog.org/pldoc/man?section=strings
In http://www.pathwayslms.com/swipltuts/dcg/#anch1 you have this DCG
(but also check the cliche example)
fizz_buzz(Msg) --> anything, fizz(Msg), anything, buzz, anything.
anything --> [].
anything --> [_], anything.
fizz(Msg) -->
"fizz",
{
format('At fizz we have Msg=wn', [Msg])
}.
buzz -->
"buzz".
Now trying this:
Str = "fizzbuzz”, phrase(fizz_buzz(patat),Str).
results in:
ERROR: Type error: list' expected, found
"fizzbuzz"' (a string)
This though, works:
?- phrase(fizz_buzz(patat),X).
At fizz we have Msg=patat
X = [102, 105, 122, 122, 98, 117, 122, 122] ;
AND also:
phrase(fizz_buzz(patat),X).[102, 105, 122, 122, 98, 117, 122, 122]).
The first one only works after
?- set_prolog_flag(double_quotes, codes).
true.
As we see here:
?- phrase(fizz_buzz(patat),"fizzbuzz").
At fizz we have Msg=patat
true
Now may we conclude that inside DCG’s SWI Prolog always interprets
double quoted strings as lists of character codes, but in a QUERY you’d
better set your double_quotes flag properly! An example of which
here would certainly save time in searching the dense manual BTW.
Finally you use phrase/3, not phrase/2 in an example before having explained that:
?- phrase(cliche, X, []),
format('~s~n', [X]).
Enjoying your stuff though (^_^)
Bye for now,
Henk
Thank you very much for making available your DCG tutorial.
I have a question, you write: "For complex grammars it's often worthwhile to first lexically parse tokens, and then parse that token stream for the real grammar."
However, there is no explanation what lexical parsing is, no examples, and it is not clear whether it can be done in Prolog.
It would be tremendously helpful if the tutorial could be expanded with an illustrative example or at least provide some pointers.
With best regards,
Parker
the tutorial could use some good words on semantic issues -
notably, what constitutes good output of a lexical analyzer, and what constitutes a good AST.
if the suffixes don't match it just matches 'anything' - suspect the 'anything' got added later.
Ooops!
point of exercise is that the args have to be the same.
and other nlp predicates
Hi Anne,
thank you for the great tutorial! Unfortunately I could not find any information about its license. The same for your other tutorials. Would it be possible to provide a LICENSE.md
file?
Thank you,
Falco
Cover pack dcgutils
Why aren't cuts mentioned?
Use tabling, or pass part parsed so far in to recursive call.
https://groups.google.com/forum/#!topic/swi-prolog/5CoQLxXcI3A
In section 11.4 of the tutorial, you examine uses of tuples_in. I have tried to write a program for exercise 1 of that section, using tuples_in, but I encounter the dreaded ‘Arguments are not sufficiently instantiated’ error. I wrote a successful version of the program using recursion (i.e. define a one-ride path; then a path from A to B is a one-ride path from A to I and a path from I to B), but I just used member to check that each leg is a valid ride.
http://www.pathwayslms.com/swipltuts/dcg/index.html#anchintro
some_terminals --> [this, is, a, teminal],
We shall use the nonterminal as//0
Notation : A DCG head with functor f and arity N is referred to as f//N to distinguish it from a regular Prolog predicate, which we refer to as f/N. : should be said early !!!!!!!!!!
1_4 Variables in Body : more details welcome !!!!!!!!
Two other remarks regarding phrase/2:
You write:
To execute a grammar rule, we use Prolog's built-in phrase/2 predicate.
The first argument is a DCG body.
phrase(Body, Ls) is true iff Body describes the list Ls.
BUT that first argument is the HEAD of the/a “top" rule of a DCG, isn’t it?
(It can be the head of a lower rule too of course, if you want to test/find
substructures of a DCG.)
Maybe it’s clearer to replace "iff Body describes” with "iff (sub)DCG describes”?
need to rewrite dcg tutorial to cover
phrase_from_stream(:Grammer, +Stream)
syntax_error(+Error)//
lazy_list_location(-Location)//
lazy_list_character_count(-CharCount)//
This means not only rewrite of error location reporting, but dealing with phrase_from_stream as option for list processing.
phrase(cliche, X, []) is used without explaining the arity 3 version of phrase/2
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.