-- Written by Gabriel Dos Reis (gdr AT cs DOT tamu DOT edu) -- Last modified on Jan 15, 2007. -- -- This file contains a low-level code for parsing -- a Spad source file into an internal AST. The -- AST, for the entire file, is presented as a list of -- toplevel statements (mostly definitions). -- Since this is low-level code, I don't expect people -- to get here, and you cannot 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 gdr-spad-parser.spad. -- -- To use this file: -- (1) translate it to Common Lisp, with bootsys: -- bootsys -batch -eval '(boottran::boottoclc "gdr-reader.boot")' -- -- (2) compile gdr-spad-parser.spad -- -- gdrParseSpadFile sourceFile == $SPAD : local := true -- we are parsing Spad, $BOOT : local := false -- not Boot. OUT_-STREAM := _*STANDARD_-OUTPUT_* -- spit any noise to -- the standard output -- we need to tell the post-parsing transformers that we're compiling; -- few parse forms have slightly different representations -- depending on whether we are in interpreter mode or compiler mode. savedInteractiveMode := $InteractiveMode $InteractiveMode := false oldParserAutoloadOnceTrigger() -- load parsing functions oldCompilerAutoloadOnceTrigger() INIT_-BOOT_/SPAD_-READER() savedInStream := IN_-STREAM -- we need to restore the -- global input stream state -- after we finished messing -- with it IN_-STREAM := MAKE_-INSTREAM sourceFile INITIALIZE_-PREPARSE IN_-STREAM asts := [] -- accumulates parse trees -- for all definitions in -- sourceFile. while ^(_*EOF_* or FILE_-CLOSED) repeat BOOT_-LINE_-STACK := PREPARSE IN_-STREAM LINE := CDAR BOOT_-LINE_-STACK PARSE_-NewExpr() pt := POP_-STACK_-1() -- get the parse tree pf := postTransform pt -- turn it into a parse form ast := parseTransform pf -- finally into an AST asts := cons([pf, ast], asts) IOCLEAR(IN_-STREAM, OUT_-STREAM) SHUT IN_-STREAM IN_-STREAM := savedInStream $InteractiveMode := savedInteractiveMode -- we accumulated the parse trees in reverse order -- of declarations. reverse asts