Definite Clause Grammars (DCGs)

Sdílet
Vložit
  • čas přidán 20. 07. 2022
  • Prolog has a built-in grammar mechanism, Definite Clause Grammars (DCGs). A DCG describes a sequence, and allows us to conveniently reason about sequences manifested as lists. DCGs are a very versatile mechanism, and one of Prolog's greatest attractions. We use them for parsing, describing output, passing arguments implicitly, reading from files, and several other applications. More information: www.metalevel.at/prolog/dcg
  • Věda a technologie

Komentáře • 22

  • @ngruhn
    @ngruhn Před 2 lety +3

    Excellent video as usual. Especially the later stuff on semicontext notation was completely new to me. Very interesting.

  • @wowzers1237____
    @wowzers1237____ Před 2 lety +6

    Yesss finally! Thanks Markus!

  • @papagvasexy
    @papagvasexy Před 2 lety +1

    Recently got really interested in DCG’s, luckily, your video just came out. Great work as usual

  • @thulsadum
    @thulsadum Před rokem +2

    Really well explanation on DCGs. Thank you.

  • @mikeamy4649
    @mikeamy4649 Před 2 lety +1

    Highly enlightening. I'm grateful because I was having trouble writing a VM bytecode analyser, but now I realise that I can write it more easily and powerfully using DCGs. Luckily I didn't get too far into it.
    Oops, I mean 'describe' the bytecode.

  • @SylvainSoliman
    @SylvainSoliman Před 2 lety +1

    I think that thanks to this video I actually finally understood what I _don't_ like about DCGs (sorry). As pointed out, DCGs are very imperative!
    They are sensitive to they execution strategy, they allow for the direct translation of imperative algorithms… You can think of this as positive features, but… I guess that's why they don't feel natural to me in Prolog ^^

  • @audunstolpe7408
    @audunstolpe7408 Před rokem

    Very interesting. Hard to find elsewhere. New book badly needed.

  • @froreyfire
    @froreyfire Před 2 lety +2

    That's a nice creek in 46:30, but I wonder if it was intended? 🙂

  • @GianMarcoLeone
    @GianMarcoLeone Před rokem +1

    wow

  • @eignnx_1738
    @eignnx_1738 Před 2 lety

    What would it mean to use arbitrary length lists in the semicontext position? Could that be analogous to tracking "multiple worlds" of state?

  • @k9-guardian785
    @k9-guardian785 Před 2 lety

    I was wondering about why seq//1 leaves behind a choice point. In SWI-prolog, the equivalent is string//1.
    string([]) -->
    [].
    string([H|T]) -->
    [H],
    string(T).
    Logically there's no reason for these queries to leave choice points.
    4 ?- phrase(string(S), "").
    S = [] ;
    false.
    5 ?- phrase(string(S), "a").
    S = [a] ;
    false.
    6 ?- phrase(string(S), "ab").
    S = [a, b] ;
    false.
    So I was wondering if there's a way to redefine seq//1 such that it's deterministic.

  • @bertrandduguesclin826

    I could not understand the call//1 predicate at 1:00:33. In fact what bugs me down the most is the definition of the output chars(Cs0,Cs). I did not know this could be defined in terms of list difference. I could not find any documentation about it.

  • @theloniusbuddha2776
    @theloniusbuddha2776 Před rokem

    What is the editor he is using to visualize the trees?

  • @froreyfire
    @froreyfire Před 2 lety +1

    36:53 Say you wanted the grammar to parse the + unambiguously as left-associative. What would you change?

    • @k9-guardian785
      @k9-guardian785 Před 2 lety +2

      expr(1) --> "1".
      expr(E+1) --> expr(E), "+", "1".
      Would be left associative I believe. Even though it's left recursive it doesn't require tabling as long as you wrap your phrase call in once/1.

  • @JoeTaber
    @JoeTaber Před 2 lety +1

    My `tags//1` definition for the viewer exercise at 25:00
    tags([]) --> [].
    tags([element(Tag,_,Children)|Siblings]) --> [Tag],tags(Children),tags(Siblings).

    • @bertrandduguesclin826
      @bertrandduguesclin826 Před rokem

      tags([]) --> [].
      tags([element(Tag,_,Children)|Siblings]) --> [Tag],tags(Children),tags(Siblings),{!}.
      tags([String|Siblings]) --> [String],tags(Siblings).

  • @davidemontani9252
    @davidemontani9252 Před rokem

    why if i write phrase(xy, "XXX") it says list expected? if i put a variable he write me a list of the character accepted in ascii code

  • @leswine1582
    @leswine1582 Před 7 měsíci

    im using swipl and am trying some of the string examples you showed but it aint working. Maybe I didnt import a library or something

    • @leswine1582
      @leswine1582 Před 7 měsíci

      it works in scryer-prolog though. Maybe its dcg/basics for swipl?

    • @ThePowerOfProlog
      @ThePowerOfProlog  Před 7 měsíci +1

      @@leswine1582 Yes, I highly recommend using Scryer Prolog or one of the other modern Prolog systems which all handle the shown cases excellently!

  • @valcron-1000
    @valcron-1000 Před 2 lety +1

    12:50 In Haskell: f n = replicateM n ['X', 'Y']