Hi Doug,

> I keep going back and forth on that, trying to think of a terse syntax
> that will accommodate all the cases :-/

Idea: You could make the body _atomic_ for terminal facts.

With that, the syntax of the previous version

   (dcg noun [cat])

would become

   (dcg noun . cat)


For non-terminals, you'd have two syntax variants:

The first one is as before

   (dcg foo  mumble bar)

which expands to

   (be foo ("@In" "@Out")
      (mumble "@In" "@1")
      (bar "@1" "@Out") )

and the second one

   (dcg foo (@A) (mumble) (bar @A))

which expands to

   (be foo (@A "@In" "@Out")
      (mumble "@In" "@1")
      (bar @A "@1" "@Out") )


This syntax can be handled with

   (de dcg CL
      (clause
         (if (atom (cdr CL))
            (list
               (car CL)
               (list (cons (cdr CL) '"@A") '"@A") )
            (if (atom (cadr CL))
               (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)) ) )
               (cons
                  (car CL)
                  (append (cadr CL) '("@In" "@Out"))
                  (let Vars
                     (make
                        (link "@In")
                        (for (I . @) (cdddr CL)
                           (link (pack "@" I)) )
                        (link "@Out") )
                     (mapcar
                        '((L V1 V2)
                           (append L (cons V1) (cons V2)) )
                        (cddr CL)
                        Vars
                        (cdr Vars) ) ) ) ) ) ) )

The previous examples would then be:

   (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)

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

Reply via email to