diff --git a/books/bookvol9.pamphlet b/books/bookvol9.pamphlet index 2fc5268..b34e59e 100644 --- a/books/bookvol9.pamphlet +++ b/books/bookvol9.pamphlet @@ -4598,6 +4598,83 @@ always positioned ON the first character. \end{chunk} +\subsection{Parsing token} +\defstruct{token} +A token is a Symbol with a Type. +The type is either NUMBER, IDENTIFIER or SPECIAL-CHAR. +NonBlank is true if the token is not preceded by a blank. +\begin{chunk}{initvars} +(defstruct token + (symbol nil) + (type nil) + (nonblank t)) + +\end{chunk} + +\defvar{prior-token} +\usesstruct{prior-token}{token} +\begin{chunk}{initvars} +(defvar prior-token (make-token) "What did I see last") + +\end{chunk} + +\defvar{nonblank} +\begin{chunk}{initvars} +(defvar nonblank t "Is there no blank in front of the current token.") + +\end{chunk} + +\defvar{current-token} +\usesstruct{current-token}{token} +\begin{chunk}{initvars} +(defparameter current-token (make-token) "Token at head of input stream.") + +\end{chunk} + +\defvar{next-token} +\usesstruct{next-token}{token} +\begin{chunk}{initvars} +(defvar next-token (make-token) "Next token in input stream.") + +\end{chunk} + +\defvar{valid-tokens} +\usesstruct{valid-tokens}{token} +\begin{chunk}{initvars} +(defvar valid-tokens 0 "Number of tokens in buffer (0, 1 or 2)") + +\end{chunk} + +\defun{token-install}{token-install} +\usesstruct{token-install}{token} +\begin{chunk}{defun token-install} +(defun token-install (symbol type token &optional (nonblank t)) + (setf (token-symbol token) symbol) + (setf (token-type token) type) + (setf (token-nonblank token) nonblank) + token) + +\end{chunk} + +\defun{token-print}{token-print} +\usesstruct{token-print}{token} +\begin{chunk}{defun token-print} +(defun token-print (token) + (format out-stream "(token (symbol ~S) (type ~S))~%" + (token-symbol token) (token-type token))) + +\end{chunk} + +\subsection{Parsing reduction} +\defstruct{reduction} +A reduction of a rule is any S-Expression the rule chooses to stack. +\begin{chunk}{initvars} +(defstruct (reduction (:type list)) + (rule nil) ; Name of rule + (value nil)) + +\end{chunk} + \chapter{Parse Transformers} \section{Direct called parse routines} \defun{parseTransform}{parseTransform} @@ -11260,6 +11337,20 @@ loop \end{chunk} \subsection{Stacking and retrieving reductions of rules.} +\defvar{reduce-stack} +Stack of results of reduced productions. +\usesstruct{reduce-stack}{stack} +\begin{chunk}{initvars} +(defparameter reduce-stack (make-stack) ) + +\end{chunk} + +\defmacro{reduce-stack-clear} +\begin{chunk}{defmacro reduce-stack-clear} +(defmacro reduce-stack-clear () `(stack-load nil reduce-stack)) + +\end{chunk} + \defun{push-reduction}{push-reduction} \calls{push-reduction}{stack-push} \calls{push-reduction}{make-reduction} @@ -14213,6 +14304,7 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defmacro pop-stack-2} \getchunk{defmacro pop-stack-3} \getchunk{defmacro pop-stack-4} +\getchunk{defmacro reduce-stack-clear} \getchunk{defmacro stack-/-empty} \getchunk{defmacro star} @@ -14558,6 +14650,8 @@ if \verb|$InteractiveMode| then use a null outputstream \getchunk{defun storeblanks} \getchunk{defun s-process} +\getchunk{defun token-install} +\getchunk{defun token-print} \getchunk{defun try-get-token} \getchunk{defun underscore} diff --git a/changelog b/changelog index 9aaa0c9..6a26aaf 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +20110220 tpd src/axiom-website/patches.html 20110220.04.tpd.patch +20110220 tpd src/interp/parsing.lisp treeshake compiler +20110220 tpd books/bookvol9 treeshake compiler 20110220 tpd src/axiom-website/patches.html 20110220.03.tpd.patch 20110220 tpd src/interp/parsing.lisp treeshake compiler 20110220 tpd books/bookvol9 treeshake compiler diff --git a/src/axiom-website/patches.html b/src/axiom-website/patches.html index 20eb6ff..ff17328 100644 --- a/src/axiom-website/patches.html +++ b/src/axiom-website/patches.html @@ -3401,5 +3401,7 @@ books/bookvol9 treeshake compiler
books/bookvol5 move numericFailure code for plot3d
20110220.03.tpd.patch books/bookvol9 treeshake compiler
+20110220.04.tpd.patch +books/bookvol9 treeshake compiler
diff --git a/src/interp/parsing.lisp.pamphlet b/src/interp/parsing.lisp.pamphlet index 11194ea..f1e7e3c 100644 --- a/src/interp/parsing.lisp.pamphlet +++ b/src/interp/parsing.lisp.pamphlet @@ -17,63 +17,9 @@ \chapter{META/LISP Parser Generator and Lexical Analysis Utilities (Parsing)} \subsection{Stack} \subsection{Token} -\begin{chunk}{*} -(defstruct Token - "A token is a Symbol with a Type. - The type is either NUMBER, IDENTIFIER or SPECIAL-CHAR. - NonBlank is true if the token is not preceded by a blank." - (Symbol nil) - (Type nil) - (NonBlank t)) - -(defparameter Prior-Token (make-token) "What did I see last") - -(defparameter nonblank t "Is there no blank in front of the current token.") - -(defparameter Current-Token (make-token) "Token at head of input stream.") - -(defparameter Next-Token (make-token) "Next token in input stream.") - -(defparameter Valid-Tokens 0 "Number of tokens in buffer (0, 1 or 2)") - -(defun Token-Install (symbol type token &optional (nonblank t)) - (setf (token-symbol token) symbol) - (setf (token-type token) type) - (setf (token-nonblank token) nonblank) - token) - -(defun Token-Print (token) - (format out-stream "(token (symbol ~S) (type ~S))~%" - (Token-Symbol token) (Token-Type token))) - -\end{chunk} \subsection{Reduction} -\begin{chunk}{*} -(defstruct (Reduction (:type list)) - "A reduction of a rule is any S-Expression the rule chooses to stack." - (Rule nil) ; Name of rule - (Value nil)) - -\end{chunk} \section{Recursive descent parsing support routines} \subsection{Stacking and retrieving reductions of rules.} -\begin{chunk}{*} -(defparameter Reduce-Stack (make-stack) "Stack of results of reduced productions.") - -(defun reduce-stack-show () - (let ((store (stack-store reduce-stack)) (*print-pretty* t)) - (if store - (progn - (format t "~%Reduction stack contains:~%") - (mapcar #'(lambda (x) - (if (eq (type-of x) 'token) - (describe x) - (print x))) - (stack-store reduce-stack))) - (format t "~%There is nothing on the reduction stack.~%")))) - -(defmacro reduce-stack-clear () `(stack-load nil reduce-stack)) - (defmacro sequence (subrules &optional (actions nil)) `(and ,(pop subrules) . ,(append (mapcar #'(lambda (x) (list 'must x)) subrules)