Coder Social home page Coder Social logo

swipldcgtut's Introduction

swipldcgtut's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

swipldcgtut's Issues

Incorporate Ulrichs comments

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

strings in queries in examples

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.

phrase/3 used b efore being explained.

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

cover lexical parsing

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

example 1_3 is bogus

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.

License?

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

cuts

Why aren't cuts mentioned?

Broken exercise 11.4

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.

  • richard cameron

Need to explain first argument of phrase/2 better

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”?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.