Grammar Compiler

A simple grammar compiler ( gramcom.lsp) can compile grammar rules into parsing programs:


(defgrammar
(S ->  (what (CUST) (LOC)? ordered (PARTS)?
            (SUPP)? (DATE)?)
      (combine $2 $3 $5 $6 $7))
(S ->  (who (LOC)? ordered (PARTS)? (SUPP)? (DATE)?)
      (combine (retrieve 'customer) $2 $4 $5 $6))
(CUST ->  (customer)  (retrieve 'customer))
(CUST ->  (customers) (retrieve 'customer))
(LOC  ->  (in (city)) (restrict 'customer-city $2))
(DATE ->  (in (month))
                     (restrictb '= 'date-month $2))
(DATE ->  (before (month))
                     (restrictb '<  'date-month $2))
(DATE ->  (after (month))
                     (restrictb '>  'date-month $2))
(PARTS ->  ((part))   (restrict 'part $1))
(SUPP ->  (from (supplier)) (restrict 'supplier $2))
)

Contents    Page-10    Prev    Next    Page+10    Index