Permalink
Browse files

initial import

  • Loading branch information...
FrankBuss committed Feb 28, 2006
0 parents commit 12f29c7abdc9d1f554255246ce33cc1735293d7a
Showing with 9,920 additions and 0 deletions.
  1. +1,313 −0 lispbuilder-clawk/clawk.lisp
  2. +21 −0 lispbuilder-clawk/clawk.system
  3. +7 −0 lispbuilder-clawk/clawk.translations
  4. +178 −0 lispbuilder-clawk/clawktest.lisp
  5. +6 −0 lispbuilder-clawk/emp.data
  6. +333 −0 lispbuilder-clawk/index.html
  7. +24 −0 lispbuilder-clawk/license.txt
  8. +12 −0 lispbuilder-clawk/lispbuilder-clawk.asd
  9. +75 −0 lispbuilder-clawk/packages.lisp
  10. +75 −0 lispbuilder-lexer/index.html
  11. +276 −0 lispbuilder-lexer/lexer.lisp
  12. +19 −0 lispbuilder-lexer/lexer.system
  13. +6 −0 lispbuilder-lexer/lexer.translations
  14. +24 −0 lispbuilder-lexer/license.txt
  15. +11 −0 lispbuilder-lexer/lispbuilder-lexer.asd
  16. +13 −0 lispbuilder-lexer/packages.lisp
  17. +1,188 −0 lispbuilder-regex/closure.lisp
  18. +234 −0 lispbuilder-regex/gen.lisp
  19. +226 −0 lispbuilder-regex/index.html
  20. +24 −0 lispbuilder-regex/license.txt
  21. +20 −0 lispbuilder-regex/lispbuilder-regex.asd
  22. +563 −0 lispbuilder-regex/macs.lisp
  23. +865 −0 lispbuilder-regex/optimize.lisp
  24. +97 −0 lispbuilder-regex/packages.lisp
  25. +577 −0 lispbuilder-regex/parser.lisp
  26. +525 −0 lispbuilder-regex/regex.lisp
  27. +27 −0 lispbuilder-regex/regex.system
  28. +6 −0 lispbuilder-regex/regex.translations
  29. +605 −0 lispbuilder-regex/regexp-test-suite.lisp
  30. +215 −0 lispbuilder-regex/retest.lisp
  31. +86 −0 lispbuilder-regex/speedtest.c
  32. +19 −0 lispbuilder-yacc/COPYING
  33. +11 −0 lispbuilder-yacc/README
  34. +392 −0 lispbuilder-yacc/cl-yacc.texi
  35. +393 −0 lispbuilder-yacc/index.html
  36. +10 −0 lispbuilder-yacc/lispbuilder-yacc.asd
  37. +247 −0 lispbuilder-yacc/yacc-tests.lisp
  38. +1,197 −0 lispbuilder-yacc/yacc.lisp

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,21 @@
;;; -*- Mode: Lisp; Syntax: ANSI-Common-lisp; Package: CL-USER; Base: 10 -*-
(in-package "CL-USER")
(load-logical-pathname-translations "CLAWK")
(mk:defsystem "CLAWK"
:source-extension "lisp"
:source-pathname (translate-logical-pathname "CLAWK:SRC;")
:depends-on ("REGEX")
:components (
(:file "packages")
(:file "clawk" :depends-on ("packages"))
(:file "clawktest" :depends-on ("packages" "clawk"))))
(defun lc-clawk ()
(mk:compile-system "CLAWK"))
(defun ld-clawk ()
(mk:load-system "CLAWK"))
@@ -0,0 +1,7 @@
#+:Lispworks
(setf (logical-pathname-translations "CLAWK")
'(("CLAWK:SYS;*" "d:/lisp/*")
("CLAWK:SRC;*" "d:/lisp/clawk/*")))
@@ -0,0 +1,178 @@
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CLAWK-TEST; Base: 10 -*-
(in-package :LISPBUILDER-CLAWK-TEST)
;;;
;;; Various tests, based on translations of AWK examples from the AWK
;;; book
;;;
; Chapter 1, page 1, example 1
; Print all employees that have worked this week
;
; $3 > 0 { print $1 $2 $3 }
;
(defun test-1-1-1 (&optional (filename "emp.data"))
(for-file-lines (filename)
(with-fields ((name payrate hrsworked))
(when ($> hrsworked 0)
($print name payrate hrsworked)))))
; alternatively like this
(defun test-1-1-2 (&optional (filename "emp.data"))
(for-file-fields (filename (name payrate hrsworked))
(when ($> hrsworked 0)
($print name payrate hrsworked))))
; or this
(defun test-1-1-3 (&optional (filename "emp.data"))
(for-file-fields (filename)
(when ($> $3 0) ($print $1 $2 $3))))
; or even like this
(defawk test-1-1-4 ()
"Print out the employees that have worked this week."
(($> $3 0) ($print $1 $2 $3)))
(defun test-1-2 (&optional (filename "emp.data"))
(for-file-lines (filename)
(with-fields ((name payrate hrsworked))
(when ($zerop hrsworked)
($print name payrate hrsworked)))))
;;; also awk-like
(defawk test-1-6 ()
(t ($print *NR* $0)))
(defun test-1-7 (&optional (filename "emp.data"))
(for-file-lines (filename)
(with-fields ((name payrate hrsworked))
($print "total pay for" name "is" ($* payrate hrsworked)))))
(defun test-1-9 (&optional (filename "emp.data"))
(for-file-lines (filename inf line)
(with-fields ((name payrate hrsworked))
(declare (ignore name hrsworked))
(when ($>= payrate 5)
($print line)))))
; as close to the original awk as possible
(defawk test-1-11-1 ()
((/= *NF* 3) ($print $0 "number of fields is not equal to 3"))
(($< $2 3.35) ($print $0 "rate is below minimum wage"))
(($> $2 10) ($print $0 "rate exceeds $10 per hour"))
(($< $3 0) ($print $0 "negative hours worked"))
(($> $3 60) ($print $0 "too many hours worked")) )
; as close to the original awk as possible
(defawk test-1-11-2 ()
(BEGIN ($print "NAME RATE HOURS")
($print))
(t ($print $0)) ) ; empty condition
(defun test-1-12-1 (&optional (filename "emp.data") &aux (emp 0))
(for-file-lines (filename)
(with-fields ((name payrate hrsworked))
(declare (ignore name payrate))
(when ($> hrsworked 15)
(incf emp))))
($print emp "employees worked more than 15 hours"))
(defawk test-1-12-3 (&aux (pay 0))
(t (incf pay ($* $2 $3)))
(END ($print *NR* "employees")
($print "total pay is" pay)
($print "average pay is" (/ pay *NR*))))
(defun sample (filename &aux (pay 0) (nr 0))
(for-file-fields (filename (name payrate hrsworked))
(declare (ignore name))
(incf pay (* (num payrate) (num hrsworked)))
(incf nr) )
(format t "~%~D employees" nr)
(format t "~%total pay is ~F" pay)
(format t "~%average pay is ~F" (/ pay nr)) )
(defun test-1-12-4 (&optional (filename "emp.data") &aux maxrate maxemp)
(for-file-lines (filename)
(with-fields ((name payrate hrsworked))
(declare (ignore hrsworked))
(when ($> payrate maxrate)
(setq maxrate payrate maxemp name))))
($print "highest hourly rate:" maxrate "for" maxemp))
(defun test-1-13-1 (&optional (filename "emp.data") &aux names)
(for-file-lines (filename)
(with-fields ((name payrate hrsworked))
(declare (ignore payrate hrsworked))
(setq names ($++ names name " "))))
($print names))
(defun test-1-13-2 (&optional (filename "emp.data") &aux last)
"Print last line"
(for-file-lines (filename inf line)
(setq last line))
($print last))
(defun test-1-14-1 (&optional (filename "emp.data"))
(for-file-lines (filename)
(with-fields ((name payrate hrsworked))
(declare (ignore payrate hrsworked))
($print name ($length name)))))
(defun test-1-14-2 (filename &aux (nc 0) (nw 0))
"Count lines, words, and characters"
(setq *NR* 0) ; the low-level macros don't do this for you
(for-file-lines (filename inf line)
(with-fields ((&rest rest))
(declare (ignore rest))
(incf nc (1+ (length line)))
(incf nw *NF*)))
($print *NR* "lines," nw "words," nc "characters"))
(defun test-1-14-3 (&optional (filename "emp.data") &aux (n 0) (pay 0))
(for-file-lines (filename)
(with-fields ((name payrate hrsworked))
(declare (ignore name))
(when ($> payrate 6)
(incf n)
(incf pay ($* payrate hrsworked)))))
(if (> n 0)
($print n "employees, total pay is" pay "average pay is" (/ pay n))
($print "no employees are paid more than $6/hour")))
; doesn't use emp.data
(defun test-1-15 (filename)
"Input lines: amount rate years"
(for-file-lines (filename inf line)
(with-fields ((&optional amount rate years))
($print line)
(loop for i from 1 by 1
while ($<= i years)
do (format t "~%~t~.2F" ($* amount ($expt ($+ 1 rate) i)))))))
(defun test-1-16-2-1 (filename &aux lines)
"Print lines in reverse order"
(for-file-lines (filename inf line)
(push line lines))
(loop for line in lines
do ($print line)))
;; even more like the original awk, but not as quick
(defawk test-1-16-2-2 (&aux (lines ($array)))
"Print lines in reverse order"
(t (setf ($aref lines *NR*) $0))
(END (loop for i from *NR* above 0
do ($print ($aref lines i)))))
(defun test-1-17-3-1 (filename)
"Print the last field of every input line"
(for-file-lines (filename)
(with-fields ((&rest fields))
($print (elt fields (1- *NF*))))))
; even more like awk
(defawk test-1-17-3-2 ()
(t ($print ($n *NF*))))
@@ -0,0 +1,6 @@
Beth 4.00 0
Dan 3.75 0
Kathy 4.00 10
Mark 5.00 20
Mary 5.50 22
Suzie 4.25 18
Oops, something went wrong.

0 comments on commit 12f29c7

Please sign in to comment.