aboutsummaryrefslogtreecommitdiff
path: root/src/interp
diff options
context:
space:
mode:
Diffstat (limited to 'src/interp')
-rw-r--r--src/interp/ChangeLog6
-rw-r--r--src/interp/Makefile.in7
-rw-r--r--src/interp/Makefile.pamphlet7
-rw-r--r--src/interp/spad-parser.boot94
4 files changed, 110 insertions, 4 deletions
diff --git a/src/interp/ChangeLog b/src/interp/ChangeLog
index 700dbfef..ebaf84a0 100644
--- a/src/interp/ChangeLog
+++ b/src/interp/ChangeLog
@@ -1,3 +1,9 @@
+2007-11-15 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
+ * Makefile.pamphlet (OBJS): Include spad-parser.$(FASLEXT).
+ (spad-parser.$(FASLEXT)): New rule.
+ * spad-parser.boot: New file.
+
2007-11-13 Gabriel Dos Reis <gdr@cs.tamu.edu>
* Makefile.pamphlet (br-search.$(FASLEXT)): New rule.
diff --git a/src/interp/Makefile.in b/src/interp/Makefile.in
index 190ce68a..e79389ba 100644
--- a/src/interp/Makefile.in
+++ b/src/interp/Makefile.in
@@ -72,7 +72,7 @@ OBJS= vmlisp.$(FASLEXT) hash.$(FASLEXT) \
packtran.$(FASLEXT) pathname.$(FASLEXT) \
pf2sex.$(FASLEXT) pile.$(FASLEXT) \
posit.$(FASLEXT) property.$(FASLEXT) \
- ptrees.$(FASLEXT) \
+ ptrees.$(FASLEXT) spad-parser.$(FASLEXT) \
record.$(FASLEXT) \
rulesets.$(FASLEXT) \
scan.$(FASLEXT) serror.$(FASLEXT) \
@@ -579,7 +579,10 @@ server.$(FASLEXT): server.boot macros.$(FASLEXT)
## The old parser component roughtly is:
##
-parse.$(FASLEXT): parse.boot postpar.$(FASLEXT)
+spad-parser.$(FASLEXT): spad-parser.boot parse.$(FASLEXT)
+ $(BOOTSYS) -- --compile --output=$@ --load-directory=. $<
+
+parse.$(FASLEXT): parse.boot metalex.$(FASLEXT) postpar.$(FASLEXT)
$(BOOTSYS) -- --compile --boot="old" --output=$@ --load-directory=. $<
postpar.$(FASLEXT): postpar.boot postprop.$(FASLEXT)
diff --git a/src/interp/Makefile.pamphlet b/src/interp/Makefile.pamphlet
index b30cc054..c178279e 100644
--- a/src/interp/Makefile.pamphlet
+++ b/src/interp/Makefile.pamphlet
@@ -341,7 +341,7 @@ OBJS= vmlisp.$(FASLEXT) hash.$(FASLEXT) \
packtran.$(FASLEXT) pathname.$(FASLEXT) \
pf2sex.$(FASLEXT) pile.$(FASLEXT) \
posit.$(FASLEXT) property.$(FASLEXT) \
- ptrees.$(FASLEXT) \
+ ptrees.$(FASLEXT) spad-parser.$(FASLEXT) \
record.$(FASLEXT) \
rulesets.$(FASLEXT) \
scan.$(FASLEXT) serror.$(FASLEXT) \
@@ -1156,7 +1156,10 @@ server.$(FASLEXT): server.boot macros.$(FASLEXT)
## The old parser component roughtly is:
##
-parse.$(FASLEXT): parse.boot postpar.$(FASLEXT)
+spad-parser.$(FASLEXT): spad-parser.boot parse.$(FASLEXT)
+ $(BOOTSYS) -- --compile --output=$@ --load-directory=. $<
+
+parse.$(FASLEXT): parse.boot metalex.$(FASLEXT) postpar.$(FASLEXT)
$(BOOTSYS) -- --compile --boot="old" --output=$@ --load-directory=. $<
postpar.$(FASLEXT): postpar.boot postprop.$(FASLEXT)
diff --git a/src/interp/spad-parser.boot b/src/interp/spad-parser.boot
new file mode 100644
index 00000000..7a26fb70
--- /dev/null
+++ b/src/interp/spad-parser.boot
@@ -0,0 +1,94 @@
+-- Copyright (C) 2007, Gabriel Dos Reis.
+-- All rights reserved.
+--
+-- Redistribution and use in source and binary forms, with or without
+-- modification, are permitted provided that the following conditions are
+-- met:
+--
+-- - Redistributions of source code must retain the above copyright
+-- notice, this list of conditions and the following disclaimer.
+--
+-- - Redistributions in binary form must reproduce the above copyright
+-- notice, this list of conditions and the following disclaimer in
+-- the documentation and/or other materials provided with the
+-- distribution.
+--
+-- - Neither the name of The Numerical ALgorithms Group Ltd. nor the
+-- names of its contributors may be used to endorse or promote products
+-- derived from this software without specific prior written permission.
+--
+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+-- IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
+-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+-- EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+-- PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+-- This file contains a low-level code for parsing a Spad source file
+-- into an internal AST. Please note that this AST is the AST used by
+-- the Spad compiler, which is different from the AST used by the
+-- interpreter (a VAT). The AST, for the entire file, is a List Syntax
+-- Since this is low-level code, I don't expect people to get here,
+-- and you should directly use it. If you think, you need to get to
+-- here, then something is already wrong.
+-- There is a higher-level interface, written in SPAD, to this
+-- code. See the algebra file spad-parser.spad.
+--
+-- -- gdr/2007-11-02
+--
+
+import '"metalex"
+import '"parse"
+)package "BOOT"
+
+++ Given a pathname to a source file containing Spad code, returns
+++ a list of (old) AST objects representing the toplevel expressions
+++ in that file.
+++ ??? system commands are still executed even if they may not be
+++ ??? meaningful. Eventually this code will go away when we
+++ ??? finally use the new parser everwhere.
+parseSpadFile sourceFile ==
+ $SPAD := true -- we are parsing Spad,
+ $BOOT := false -- not Boot.
+ SETQ(_*EOF_*, false) -- end of current input?
+ FILE_-CLOSED : local := false -- current stream closed?
+
+ OUT_-STREAM : local := _*STANDARD_-OUTPUT_* -- noise to standard output
+ -- we need tell the post-parsing transformers that we're compiling
+ -- because few parse forms have slightly different representations
+ -- depending on whether we are interpreter mode or compiler mode.
+ savedInteractiveMode := $InteractiveMode
+ $InteractiveMode := false
+ INIT_-BOOT_/SPAD_-READER()
+ -- we need to restore the global input stream state after we
+ -- finished messing with it.
+ savedInStream := (IN_-STREAM : local)
+
+ -- If soureFile cannot be processed for whatever reasons
+ -- get out of here instead of being stuck later.
+ not (IN_-STREAM := MAKE_-INSTREAM sourceFile) =>
+ $InteractiveMode := savedInteractiveMode
+ IN_-STREAM := savedInStream
+ systemError '"cannot open input source file"
+ INITIALIZE_-PREPARSE IN_-STREAM
+
+ -- gather parse trees for all toplevel expressions in sourceFile.
+ asts := []
+ while ^(_*EOF_* or FILE_-CLOSED) repeat
+ BOOT_-LINE_-STACK : local := PREPARSE IN_-STREAM
+ LINE : local := CDAR BOOT_-LINE_-STACK
+ PARSE_-NewExpr()
+ asts := [parseTransform postTransform POP_-STACK_-1(), :asts]
+ -- clean up the mess, and get out of here
+ IOCLEAR(IN_-STREAM, OUT_-STREAM)
+ SHUT IN_-STREAM
+ IN_-STREAM := savedInStream
+ $InteractiveMode := savedInteractiveMode
+ -- we accumulated the parse trees in reverse order
+ nreverse asts
+