Hi Doug,

> What's the best way to handle Definite Clause Grammar syntax in pilog?
> ...
> So, I'm hoping for some pilog rules or a macro maybe that can handle
> the --> (or equivalent) of DCG in pilog :-)

I don't fully understand the context or purpose, but

   http://en.wikipedia.org/wiki/Definite_clause_grammar

says that "DCG notation is just syntactic sugar for normal definite
clauses in Prolog".

So you can write a function 'dcg' which does the necessary translation.

I would simply call 'be' here, using 'macro' because 'be' doesn't
evaluate its arguments (i.e. is a FEXPR):

   (de dcg CL
      (macro
         (be
            ^(if (pair (cadr CL))
               (list (car CL) (list (cons (caadr CL) '@A) '@A))
               (cons
                  (car CL)
                  '("@In" "@Out")
                  (let Vars
                     (make
                        (link "@In")
                        (for (I . @) (cddr CL)
                           (link (pack "@" I)) )
                        (link "@Out") )
                     (mapcar list
                        (cdr CL)
                        Vars
                        (cdr Vars) ) ) ) ) ) ) )

With that, the example in Wikipedia could be written as

   (dcg sentence  nounPhrase verbPhrase)
   (dcg nounPhrase  det noun)
   (dcg verbPhrase  verb nounPhrase)
   (dcg det [the])
   (dcg det [a])
   (dcg noun [cat])
   (dcg noun [bat])
   (dcg verb [eats])

This expands to

   : (rules 'sentence 'nounPhrase 'verbPhrase 'det 'noun 'verb)
   1 (be sentence ("@In" "@Out") (nounPhrase "@In" "@1") (verbPhrase "@1" 
"@Out"))
   1 (be nounPhrase ("@In" "@Out") (det "@In" "@1") (noun "@1" "@Out"))
   1 (be verbPhrase ("@In" "@Out") (verb "@In" "@1") (nounPhrase "@1" "@Out"))
   1 (be det ((the . @A) @A))
   2 (be det ((a . @A) @A))
   1 (be noun ((cat . @A) @A))
   2 (be noun ((bat . @A) @A))
   1 (be verb ((eats . @A) @A))
   -> verb

Does this help?

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to