unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* patch for lalr-2.0 to support guile
@ 2002-10-01  7:28 Thien-Thi Nguyen
  0 siblings, 0 replies; only message in thread
From: Thien-Thi Nguyen @ 2002-10-01  7:28 UTC (permalink / raw)
  Cc: guile-sources, guile-user

hello,

thanks for writing lalr.  it is exactly what i'm looking for (bison
replacement in scheme).  i added some bits to make it work w/ guile and
have appended the patch for your consideration in the next release of
lalr.

here is a changelog entry:

2002-09-30  Thien-Thi Nugyen  <ttn@gnu.org>

	* Makefile (any): Add support for guile.
	(guile, check-guile): New targets.
	(clean): New target.

	* ports/guile.decls: New file.

	* tests: New subdir.

	* tests/guile.test: New file.

	* README: Mention tests/ subdir.

	* lalr.skl: Fix spelling error.

i am currently working on a simple grammar to parse C header (.h) files
for possible contribution to examples/ (and use by guile), but figured
these other changes should not be held back by that work in progress.
let me know if you would prefer "diff -c" or some other format...

thi


________________________________________
cd ~/tmp/
diff -wburN lalr-2.0 lalr-2.0ttn1
diff -wburN lalr-2.0/Makefile lalr-2.0ttn1/Makefile
--- lalr-2.0/Makefile	Thu Jun 20 06:25:57 2002
+++ lalr-2.0ttn1/Makefile	Mon Sep 30 23:58:19 2002
@@ -19,6 +19,7 @@
 	@echo "   make plt-scheme"
 	@echo "   make sisc"
 	@echo "   make chicken"
+	@echo "   make guile"
 	@echo "********************"
 
 #; ---------------------------------------------------------------------- ;#
@@ -54,6 +55,24 @@
 	@echo "done."
 
 #; ---------------------------------------------------------------------- ;#
+#; Guile build                                                            ;#
+#; ---------------------------------------------------------------------- ;#
+guile:
+	@echo "building lalr.scm for guile..."
+	@./lalr.skl guile
+	@echo "done."
+check-guile:
+	@echo "checking lalr.scm for guile..."
+	@guile -s tests/guile.test `pwd`/lalr.scm
+	@echo "done."
+
+#; ---------------------------------------------------------------------- ;#
+#; clean                                                                  ;#
+#; ---------------------------------------------------------------------- ;#
+clean:
+	rm -f lalr.scm
+
+#; ---------------------------------------------------------------------- ;#
 #; documentation                                                          ;#
 #; ---------------------------------------------------------------------- ;#
 doc: 
@@ -71,3 +90,4 @@
 
 backup:
 	@tar zcf ../lalr-sources.taz *
\ No newline at end of file
+
diff -wburN lalr-2.0/README lalr-2.0ttn1/README
--- lalr-2.0/README	Thu Jun 20 06:25:01 2002
+++ lalr-2.0ttn1/README	Tue Oct  1 00:03:44 2002
@@ -8,7 +8,8 @@
  	. Makefile      : makefile for generating system-specific 
 		          parser generators.
 	. examples/     : examples of parsers (directory is currently empty)
-	. ports/        :
+	. ports/        : scheme-implementation-dependent bits
+	. tests/	: test scripts
 
 It has been successfully tested under the following Scheme systems:
 
diff -wburN lalr-2.0/documentation/lalr.html lalr-2.0ttn1/documentation/lalr.html
--- lalr-2.0/documentation/lalr.html	Thu Jun 20 06:59:40 2002
+++ lalr-2.0ttn1/documentation/lalr.html	Mon Sep 30 22:57:32 2002
@@ -146,7 +146,7 @@
 return the symbol <code>'*eoi*</code> each time it is invoked.
 
 <br><p>
-The error procedure must be a function that accepts at least to
+The error procedure must be a function that accepts at least two
 parameters.
 <p><table border="0" width="100%"><tr><td class="md"><b><font size=+3><a name="format">The grammar format</a></font></b></td></tr></table><br>
 
diff -wburN lalr-2.0/lalr.skl lalr-2.0ttn1/lalr.skl
--- lalr-2.0/lalr.skl	Thu Jun 20 06:58:42 2002
+++ lalr-2.0ttn1/lalr.skl	Tue Oct  1 00:20:01 2002
@@ -9,6 +9,7 @@
 	plt-scheme) DECLS=ports/plt-scheme.decls;;
 	sisc) DECLS=ports/sisc.decls;;
 	chicken) DECLS=ports/chicken.decls;;
+        guile) DECLS=ports/guile.decls;;
 	*) echo "invalid Scheme system: $1" ; exit 1;;
 esac
 
@@ -127,7 +128,7 @@
 ;! Once the end of file is encountered, the lexical analyzer must always  !;
 ;! return the symbol @c ('*eoi*) each time it is invoked.                 !;
 ;!                                                                        !;
-;! The error procedure must be a function that accepts at least to        !;
+;! The error procedure must be a function that accepts at least two        !;
 ;! parameters.                                                            !;
 ;; ---------------------------------------------------------------------- ;;
 ;! @section (format "The grammar format")                                 !;
diff -wburN lalr-2.0/ports/guile.decls lalr-2.0ttn1/ports/guile.decls
--- lalr-2.0/ports/guile.decls	Wed Dec 31 16:00:00 1969
+++ lalr-2.0ttn1/ports/guile.decls	Mon Sep 30 22:16:53 2002
@@ -0,0 +1,7 @@
+;; contributed by Thien-Thi Nguyen <ttn@gnu.org>
+
+(begin
+  (defmacro def-macro (form . body)
+    `(defmacro ,(car form) ,(cdr form) ,@body))
+  (def-macro (BITS-PER-WORD) 28)
+  (def-macro (logical-or x . y) `(logior ,x ,@y)))
diff -wburN lalr-2.0/tests/guile.test lalr-2.0ttn1/tests/guile.test
--- lalr-2.0/tests/guile.test	Wed Dec 31 16:00:00 1969
+++ lalr-2.0ttn1/tests/guile.test	Tue Oct  1 00:00:25 2002
@@ -0,0 +1,49 @@
+;; usage: guile -s guile.test /ABSOLUTE/PATH/TO/lalr.scm
+
+(format #t "(getcwd) => ~A\n" (getcwd))
+
+(or (and (< 1 (length (command-line)))
+         (file-exists? (cadr (command-line)))
+         (load (cadr (command-line))))
+    (error "usage: guile -s guile.test /ABSOLUTE/PATH/TO/lalr.scm"))
+
+;; from documentation example
+(define expr-parser
+  (lalr-parser
+   ;; Terminal symbols
+   (ID + - * /)
+   ;; Productions
+   (e (e + t)    : (+ $1 $3)
+      (e - t)    : (- $1 $3)
+      (t)        : $1)
+   (t (t * f)    : (* $1 $3)
+      (t / f)    : (/ $1 $3)
+      (f)        : $1)
+   (f (ID)       : $1)))
+
+(format #t "expr-parser => ~A\n" expr-parser)
+
+(define token-stream
+  '((ID . 3) (+) (ID . 3) (*) (ID . 13)))
+
+(define (lexer)
+  (let ((ret (car token-stream)))
+    (set! token-stream (cdr token-stream))
+    (if (null? token-stream)
+        (set! token-stream (list '*eoi*)))
+    ret))
+
+(define (error-handler . args)
+  (format #t "error-handler: args => ~A\n" args)
+  (exit 1))
+
+(define expected 42)
+(define actual #f)
+
+(format #t "~A => ~A\n"
+        '(expr-parser lexer error-handler)
+        (begin
+          (set! actual (expr-parser lexer error-handler))
+          actual))
+
+(exit (and (number? actual) (= expected actual)))

Compilation exited abnormally with code 1 at Tue Oct  1 00:20:16


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-10-01  7:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-10-01  7:28 patch for lalr-2.0 to support guile Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).