;;; -*- Mode: LISP; Package: :cl-user; BASE: 10; Syntax: ANSI-Common-Lisp; ;-*- ;;; Time-stamp: <2002-11-08 08:24:08> ;;; Touched: Thu Oct 10 00:29:21 2002 (in-package :CL-USER) ;;; HW4 CS555 Fall 02 for ;;; ;;; There are 4 files for this HW: ;;; hw4.lisp: this file ;;; core1.zb: surface syntax for the core lambda language (zebu grammar) ;;; fact.c: test file for the factorial function. ;;; core1-pprint.lisp: format hacks for reasonable pretty printing ;;; External Dependencies: ;;; This project uses the ZEBU parser generator package from the cmu ;;; ai repositories. Also requires mk-defsystem from clocc at ;;; soresforge. ;;; This has been tested only with cmucl and makes assumptions that ;;; the Lisp implementation used is cmucl. (defparameter *hw3-source-directory* (or (and *load-truename* (make-pathname :directory (pathname-directory *load-truename*))) (ext:default-directory))) (defparameter *hw3-binary-directory* (make-pathname :directory (append (pathname-directory *hw3-source-directory*) (list "binary")))) (ensure-directories-exist *hw3-binary-directory*) #-mk-defsystem(require :defsystem) ;; say no to defsystem (defparameter *zebu-directory* #p"/home/madhu/cmu/zebu/") #+nil(defparameter *zebu-binary-directory* *hw3-binary-directory*) (load (merge-pathnames "sysdcl.lisp" *zebu-directory*)) #+nil (progn (defparameter *zebra-directory* #p"/home/madhu/cmu/zebra/") #+nil(defparameter *zebra-binary-directory* *hw3-binary-directory*) (load (merge-pathnames "sysdcl.lisp" *zebra-directory*))) ;; fix conflicts (shadowing-import '(ZEBU-RR KB-DOMAIN)) (MAKE:defsystem "HW4" :depends-on ("ZEBU" #+nil "ZEBRA") :source-pathname *hw3-source-directory* :binary-pathname *hw3-binary-directory* :components ((:file "core1" :language :ZEBU :source-extension "zb" :binary-extension "tab" :compiler zebu-compile-file-1 :loader zebu-load-file-1) "core1-pprinters")) ; pretty print enhancement hacks ;; also compiles and loads ZEBU #+nil (MAKE:load-system 'HW4 :compile-during-load t) ;; set default grammar to the surface syntax language (setq ZB:*current-grammar* (ZB:find-grammar "core1")) ;; set comment chars for #'zb:file-parser (setq ZB:*comment-brackets* '(("(*" . "*)"))) ;;; we can read single expressions using #'zb:read-parser (let ((teststrings1 '("65656" "(abs 23452 23452)" "int `3792562706782356203'" "float `-5632789.452389e-82'" "char `f'" ; TODO escape sequences in :lex-cat "(app iadd (record [int `444' 23]))"))) (loop for str in teststrings1 do (warn "PARSING: ~A" str) (let ((result (ZB:read-parser str))) (warn "--><~A> (~A)" result (type-of result))))) ;;; read in the factorial function from fact.c (warn "~A" (setq a (zb:file-parser (merge-pathnames "fact.c" *hw3-source-directory*))))