Contents    Page-10    Prev    Next    Page+10    Index   

Grammar Compiler [file gramcom.lsp]

It is easy to write a grammar compiler that converts a Yacc-like grammar into the equivalent ATN parsing functions. This is especially easy in Lisp since Lisp code and Lisp data are the same thing.


(rulecom '(LOC  -> (in (city))
              (restrict 'customer-city $2)) )

(DEFUN LOC62 ()
  (LET ($1 $2)
    (SAVEPTR)
    (IF (AND (AND (EQL (SETQ $1 *WORD*) 'IN)
                  (NEXT))
             (SETQ $2 (CITY)))
        (PROGN (SUCCESS)
               (RESTRICT 'CUSTOMER-CITY $2))
        (FAIL))))