grammar-predicate.ss
(module grammar-predicate mzscheme
  (require (prefix grammar- "grammar-procedures.ss"))
  (provide grammar?)
  
  (define grammar?
    (let ((variable (grammar-predicate symbol?))
          (datum (grammar-predicate (lambda (object) #t)))
          (delayed-non-terminal 'ignored))
      (let ((non-terminal (lambda (x) (delayed-non-terminal x)))
            (terminal (grammar-lst 'quote datum)))
        (let ((element (grammar-alt terminal non-terminal)))
          (set! delayed-non-terminal
                (grammar-report-if-bad 'non-terminal
                  (grammar-alt variable
                    (grammar-lst 'alt (grammar-star element))
                    (grammar-lst 'seq (grammar-star element))
                    (grammar-lst 'lst (grammar-star element))
                    (grammar-lst 'star element)
                    (grammar-lst 'plus element)
                    (grammar-lst 'opt element)
                    (grammar-lst 'dot element element)
                    (grammar-lst 'predicate datum)
                    (grammar-lst 'cfa datum)
                    (grammar-lst 'report-if-bad datum non-terminal))))
          (grammar-cfa->predicate
           (grammar-report-if-bad 'grammar
             (grammar-lst 'grammar variable
               (grammar-plus
                 (grammar-report-if-bad 'production
                   (grammar-lst variable (grammar-star element)))))))))))
 
  ) ; end of module grammar-predicate