TEX-HTML-TEX-PARSING> (esrap-peg:peg-compile (esrap-peg:parse-peg-file "~/Projects/tex.peg")) FORMULATRANSCHAR TEX-HTML-TEX-PARSING> (esrap-peg:def-peg-matchers ( (Text ((_ ?x) (s+ (m! #'! (m! #'n2 ?x))))) (Paragraph ((?x _) (concatenate 'string (s+ (m! #'! ?x)) "$"))) (Entry (_ (! x))) (InParagraphEntry ((_ ?x) (! ?x))) (FormulaFriendlyEntry (_ (! x))) (MissedOperator (_ (if *in-formula* (format nil "\\~a" x) x))) (UniversallyFriendlyEntry (_ (! x))) (PlainGroup ((_ (_ (?x . ?y) _)) (! `(tex-html-tex-parsing::HPPG (,(! ?x) ,?y)))) ((_ (_ nil _)) (if *in-formula* "{}" "")) ) (HPPG (("\\it " ?y) (! `(tex-html-tex-parsing::PPG ("\\it " . ,(let ((*in-formula* nil)) (m! #'! ?y)))))) (("\\bf " ?y) (! `(tex-html-tex-parsing::PPG ("\\bf " . ,(let ((*in-formula* nil)) (m! #'! ?y)))))) ((?x ?y) (! `(tex-html-tex-parsing::PPG (,?x . ,(m! #'! ?y))))) ) (PPG (("\\it " . ?x) (if *in-formula* (progn (format t "In context: ~s~%\\it instead of \\mbox: ~s~%" x *current-context*) (format nil "{\\mbox{~{~a~}}}" ?x) ) (format nil "~{~a~}" ?x) )) (("\\bf " . ?x) (if *in-formula* (progn (format t "In context: ~s~%\\bf instead of \\mbox: ~s~%" x *current-context*) (format nil "{\\mbox{~{~a~}}}" ?x) ) (format nil "~{~a~}" ?x) )) (_ (format nil "{~{~a~}}" x))) (Group ((_ ?x _) (s+ (m! #'! ?x)))) (ProxyAssumedPlainTextChar (_ (! `(,(if *in-formula* 'tex-html-tex-parsing::FormulaStrangeChar 'tex-html-tex-parsing::AssumedPlainTextChar ) ,x)))) (CommaDecimal ((?x _ ?y) (if *in-formula* (format nil "~{~a~}{,}~{~a~}" ?x ?y) (format nil "~{~a~},~{~a~}" ?x ?y)))) (ProxyAssumedPlainTextChar (_ (if *in-formula* (or (! (list 'tex-html-tex-parsing::FormulaTransChar (n2 x))) (! (list 'tex-html-tex-parsing::FormulaStrangeChar (n2 x))) ) (! (list 'tex-html-tex-parsing::AssumedPlainTextChar x)) ))) (FormulaStrangeChar (_ (progn (format t "Strange char in formula: ~s in context ~s~%" x *current-context*) "!"))) (AssumedPlainTextChar ((_ "<") (if *in-formula* "\\lt " "<")) ((_ ">") (if *in-formula* "\\gt " ">")) ((_ " ") (if *in-formula* "" " ")) ((_ ?x) ?x)) (TextTilde (_ (if *in-formula* "~" " "))) (TextRatio ((?x _ ?y ?z) (format nil "~a:~a~a" (s+ ?x) ?y (s+ ?z)))) (FormulaPlainTextChar (_ (! `(tex-html-tex-parsing::AssumedPlainTextChar (nil ,x))))) (FormulaTransChar (_ (second (find x '( ("А" "A") ("В" "B") ("Е" "E") ("К" "K") ("М" "M") ("Н" "H") ("О" "O") ("Р" "P") ("С" "C") ("Т" "T") ("У" "Y") ("Х" "X") ("а" "a") ("е" "e") ("о" "o") ("р" "p") ("с" "c") ("у" "y") ("х" "x") ("\"" "''") ) :test 'equal :key 'first)))) (EOL (_ (if *in-formula* "" " "))) (WhiteSpace (_ " ")) (WhiteSpaceToKill (_ "")) (EOLToKill (_ "")) (Comment (_ "")) (DisplayFormula ((_ ?x _) (concatenate 'string "$" (let* ((*in-formula* t)) (! ?x)) "$"))) (InlineFormula ((_ ?x _) (concatenate 'string "" (let* ((*in-formula* t)) (! ?x)) ""))) (Command (((tex-html-tex-parsing::LongCommand ("\\" ("t" "e" "x" "t" "i" "t"))) _ _ ?x _) (concatenate 'string "" (! (n1 ?x)) "")) (((tex-html-tex-parsing::LongCommand (nil "\\" ("h" "b" "o" "x"))) _ _ ?x _) (! `(tex-html-tex-parsing::ProcessedCommand ("\\mbox" nil (,(let ((*in-formula* nil))(! (n1 ?x))))) ))) (((tex-html-tex-parsing::LongCommand (nil "\\" ("m" "b" "o" "x"))) _ _ ?x _) (! `(tex-html-tex-parsing::ProcessedCommand ("\\mbox" nil (,(let ((*in-formula* nil))(! (n1 ?x))))) ))) (((tex-html-tex-parsing::OneCharCommand ("\\" nil "'")) _ nil ((TEX-HTML-TEX-PARSING::MANDATORYARGUMENT (NIL (TEX-HTML-TEX-PARSING::GROUP ("{" ((TEX-HTML-TEX-PARSING::INPARAGRAPHENTRY (NIL ?x))) "}"))))) _) (format nil "\\'~a" (! ?x))) (((tex-html-tex-parsing::OneCharCommand ("\\" nil " ")) _ nil nil _) (if *in-formula* "\\ " " ")) (((tex-html-tex-parsing::OneCharCommand ("\\" nil ?x)) _ nil nil _) (format nil "\\~a" ?x)) ((?x _ ?y ?z ?u) (! `(tex-html-tex-parsing::ProcessedCommand (,(! ?x) ,(m! #'! ?y) ,(m! #'! ?z) ,?u))))) (NoArgCommand ((_ ?x _) (format nil "\\~a " ?x))) (ProcessedCommand (("\\textit" _ (?x . _)) (concatenate 'string "" ?x "")) (("\\begin" _ ("center")) "") (("\\end" _ ("center")) "") (("\\mbox" _ (#.(unify:make-template 'string '(string #\\ #\i #\t #\Space &rest ?x))) _) (if *in-formula* (progn (format t "In context: ~s~%\\it in mbox: ~s~%" *current-context* x) (format nil "\\mbox{~a}" ?x)) (format nil "\\hbox{\\it ~a}" ?x) )) (("\\ldots" . _) (if *in-formula* (concatenate 'string (first x) " ") (progn (format t "In context: ~s~%Dots in text: ~s~%" *current-context* x) "…"))) (("\\cdots" . _) (if *in-formula* (concatenate 'string (first x) " ") (progn (format t "In context: ~s~%Dots in text: ~s~%" *current-context* x) ""))) (("\\dots" . _) (if *in-formula* (concatenate 'string (first x) " ") (progn (format t "In context: ~s~%Dots in text: ~s~%" *current-context* x) "…"))) (("\\ddots" . _) (if *in-formula* (concatenate 'string (first x) " ") (progn (format t "In context: ~s~%Dots in text: ~s~%" *current-context* x) ""))) (("\\vdots" . _) (if *in-formula* (concatenate 'string (first x) " ") (progn (format t "In context: ~s~%Dots in text: ~s~%" *current-context* x) ""))) (("\\pdots" . _) (if *in-formula* (concatenate 'string (first x) " ") (progn (format t "In context: ~s~%Dots in text: ~s~%" *current-context* x) ""))) (("\\-" _ _) "") (("\\-" _ _ _) "") ((?x ?y ?z ?u) (format nil "~a~{[~a]~}~{{~a}~}~a" ?x (m! #'! ?y) ?z (if (or ?y ?z (and *in-formula* (not ?u))) "" " "))) ((?x ?y ?z) (format nil "~a~{[~a]~}~{{~a}~}~a" ?x (m! #'! ?y) ?z (if (or ?y ?z (and *in-formula*)) "" " "))) ) (Environment ((_ _ _ ?name _ ?opta ?stricta ?cont _ _ _ ?name _) (! `(tex-html-tex-parsing::ParsedEnvironment (,(s+ ?name) ,(m! #'! ?opta) ,(m! #'! ?stricta) ,(m! #'! ?cont)) )))) (Root ((_ _ ?n _ ?x) (format nil "\\sqrt[~{~a~}]{~a}" (m! #'! (m! #'n2 (n2 ?n))) (! (n2 (n2 ?x)))))) (LeftRight ((_ (_ (_ ?left)) _ ?cont _ (_ (_ ?right)) _) (! `(tex-html-tex-parsing::ParsedLeftRight (,(! ?left) ,(! ?right) ,?cont))))) (ParsedEnvironment ((?name ?opta ?stricta ?cont) (s+ ?cont)) ) (ParsedLeftRight (("{" "." ((_ (_ (tex-html-tex-parsing::Environment (_ _ _ ("a" "r" "r" "a" "y") . _)))) . _)) (format nil "\\syst{~{~a~}}" (cons (! (n1 (n3 x))) (let ((*in-formula* t)) (m! #'! (cdr (n3 x))))))) (("\\{" "." ((_ (_ (tex-html-tex-parsing::Environment (_ _ _ ("a" "r" "r" "a" "y") . _)))) . _)) (format nil "\\syst{~{~a~}}" (cons (! (n1 (n3 x))) (let ((*in-formula* t)) (m! #'! (cdr (n3 x))))))) (("\\{ " "." ((_ (_ (tex-html-tex-parsing::Environment (_ _ _ ("a" "r" "r" "a" "y") . _)))) . _)) (format nil "\\syst{~{~a~}}" (cons (! (n1 (n3 x))) (let ((*in-formula* t)) (m! #'! (cdr (n3 x))))))) (("[" "." ((_ (_ (tex-html-tex-parsing::Environment (_ _ _ ("a" "r" "r" "a" "y") . _)))) . _)) (format nil "\\sovok{~{~a~}}" (cons (! (n1 (n3 x))) (let ((*in-formula* t)) (m! #'! (cdr (n3 x))))))) ((?x ?y ?cont) (format nil "\\left~a~a~{~a~}\\right~a~a" (if (cl-ppcre:scan "^[A-Za-z]" ?x) " " "") ?x (m! #'! ?cont) (if (cl-ppcre:scan "^[A-Za-z]" ?y) " " "") ?y))) (StrangeEater (_ "")) (OptionalArgument ((_ _ ?x _) (s+ (m! #'n2 ?x)))) (MandatoryArgument (_ (! (n2 x)))) (OneCharCommand (("\\" _ "&") "\\amp ") (("\\" _ "|") "\\Vert ") (_ (concatenate 'string (n1 x) (n3 x)))) (LongCommand ((_ "\\" ?x) (s+ (cons "\\" ?x)))) (Formula (_ (s+ (m! #'! x)))) (ParagraphBreak (_ "$")) ) :abbreviations ( (! (x) (esrap-peg:ast-eval x)) (n1 (x) (first x)) (n2 (x) (second x)) (n3 (x) (third x)) (n4 (x) (fourth x)) (n5 (x) (fifth x)) (n6 (x) (sixth x)) (n7 (x) (seventh x)) (n8 (x) (eighth x)) (n9 (x) (ninth x)) (s+ (x) (apply 'concatenate 'string x)) (l+ (x) (apply 'append x)) (m! (f x) (mapcar f x)) ) :arg x :package :tex-html-tex-parsing) ; in: ESRAP-PEG:DEF-PEG-FUN PARSEDENVIRONMENT ; (LET ((TEX-HTML-TEX-PARSING::?CONT ; (IT.UNIMIB.DISCO.MA.CL.EXT.DACF.UNIFICATION:FIND-VARIABLE-VALUE ; 'TEX-HTML-TEX-PARSING::?CONT ESRAP-PEG::M)) ; (TEX-HTML-TEX-PARSING::?NAME ; (IT.UNIMIB.DISCO.MA.CL.EXT.DACF.UNIFICATION:FIND-VARIABLE-VALUE ; 'TEX-HTML-TEX-PARSING::?NAME ESRAP-PEG::M)) ; (TEX-HTML-TEX-PARSING::?OPTA ; (IT.UNIMIB.DISCO.MA.CL.EXT.DACF.UNIFICATION:FIND-VARIABLE-VALUE ; 'TEX-HTML-TEX-PARSING::?OPTA ESRAP-PEG::M)) ; (TEX-HTML-TEX-PARSING::?STRICTA ; (IT.UNIMIB.DISCO.MA.CL.EXT.DACF.UNIFICATION:FIND-VARIABLE-VALUE ; 'TEX-HTML-TEX-PARSING::?STRICTA ESRAP-PEG::M))) ; (TEX-HTML-TEX-PARSING::S+ TEX-HTML-TEX-PARSING::?CONT)) ; ; caught STYLE-WARNING: ; The variable ?NAME is defined but never used. ; ; caught STYLE-WARNING: ; The variable ?OPTA is defined but never used. ; ; caught STYLE-WARNING: ; The variable ?STRICTA is defined but never used. ; ; compilation unit finished ; caught 3 STYLE-WARNING conditions # TEX-HTML-TEX-PARSING> (esrap-peg:ast-eval (parse-tex (alexandria:read-file-into-string "~/Projects/Git/dpANS3/concept-arrays.tex"))) ; Evaluation aborted on #. TEX-HTML-TEX-PARSING> (setf *in-formula* nil) NIL TEX-HTML-TEX-PARSING> (setf *current-context* nil) NIL TEX-HTML-TEX-PARSING> (esrap-peg:ast-eval (parse-tex (alexandria:read-file-into-string "~/Projects/Git/dpANS3/concept-arrays.tex"))) " \\beginsubsection{Array Elements} \\DefineSection{ArrayElements}$An \\term{array} contains a set of \\term{objects} called \\term{elements} that can be referenced individually according to a rectilinear coordinate system.$\\beginsubsubsection{Array Indices}$An \\term{array} \\term{element} is referred to by a (possibly empty) series of indices. The length of the series must equal the \\term{rank} of the \\term{array}. \\issue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:ALL-FIXNUM} Each index must be a non-negative \\term{fixnum} \\endissue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:ALL-FIXNUM} less than the corresponding \\term{array} \\term{dimension}. \\term{Array} indexing is zero-origin.$\\endsubsubsection \\beginsubsubsection{Array Dimensions}$An axis of an \\term{array} is called a \\newterm{dimension}.$Each \\term{dimension} is a non-negative \\issue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:ALL-FIXNUM} \\term{fixnum}; \\endissue{ARRAY-DIMENSION-LIMIT-IMPLICATIONS:ALL-FIXNUM} if any dimension of an \\term{array} is zero, the \\term{array} has no elements. It is permissible for a \\term{dimension} to be zero, in which case the \\term{array} has no elements, and any attempt to \\term{access} an \\term{element} is an error. However, other properties of the \\term{array}, such as the \\term{dimensions} themselves, may be used.$\\beginsubsubsubsection{Implementation Limits on Individual Array Dimensions}$An \\term{implementation} may impose a limit on \\term{dimensions} of an \\term{array}, but there is a minimum requirement on that limit. \\Seevar{array-dimension-limit}.$\\endsubsubsubsection \\endsubsubsection \\beginsubsubsection{Array Rank}$ An \\term{array} can have any number of \\term{dimensions} (including zero). The number of \\term{dimensions} is called the \\newterm{rank}.$If the rank of an \\term{array} is zero then the \\term{array} is said to have no \\term{dimensions}, and the product of the dimensions (see \\funref{array-total-size}) is then 1; a zero-rank \\term{array} therefore has a single element.$\\beginsubsubsubsection{Vectors}$An \\term{array} of \\term{rank} one (\\ie a one-dimensional \\term{array}) is called a \\newterm{vector}.$\\beginsubsubsubsubsection{Fill Pointers}$A \\newterm{fill pointer} is a non-negative \\term{integer} no larger than the total number of \\term{elements} in a \\term{vector}. Not all \\term{vectors} have \\term{fill pointers}. \\Seefuns{make-array} and \\funref{adjust-array}.$An \\term{element} of a \\term{vector} is said to be \\newterm{active} if it has an index that is greater than or equal to zero, but less than the \\term{fill pointer} (if any). For an \\term{array} that has no \\term{fill pointer}, all \\term{elements} are considered \\term{active}.$Only \\term{vectors} may have \\term{fill pointers}; multidimensional \\term{arrays} may not. A multidimensional \\term{array} that is displaced to a \\term{vector} that has a \\term{fill pointer} can be created.$\\endsubsubsubsubsection \\endsubsubsubsection \\beginsubsubsubsection{Multidimensional Arrays}$\\beginsubsubsubsubsection{Storage Layout for Multidimensional Arrays}$Multidimensional \\term{arrays} store their components in row-major order; that is, internally a multidimensional \\term{array} is stored as a one-dimensional \\term{array}, with the multidimensional index sets ordered lexicographically, last index varying fastest. $\\endsubsubsubsubsection \\beginsubsubsubsubsection{Implementation Limits on Array Rank}$An \\term{implementation} may impose a limit on the \\term{rank} of an \\term{array}, but there is a minimum requirement on that limit. \\Seevar{array-rank-limit}.$\\endsubsubsubsubsection \\endsubsubsubsection \\endsubsubsection \\endsubsection \\beginsubsection{Specialized Arrays}$An \\term{array} can be a \\term{general} \\term{array}, meaning each \\term{element} may be any \\term{object}, or it may be a \\term{specialized} \\term{array}, meaning that each \\term{element} must be of a restricted \\term{type}.$The phrasing ``an \\term{array} \\term{specialized} to \\term{type} \\metavar{type}'' is sometimes used to emphasize the \\term{element type} of an \\term{array}. This phrasing is tolerated even when the \\metavar{type} is \\typeref{t}, even though an \\term{array} \\term{specialized} to \\term{type} \\term{t} is a \\term{general} \\term{array}, not a \\term{specialized} \\term{array}.$\\Thenextfigure lists some \\term{defined names} that are applicable to \\term{array} creation, \\term{access}, and information operations.$\\displaythree{General Purpose Array-Related Defined Names}{ adjust-array&array-has-fill-pointer-p&make-array\\cr adjustable-array-p&array-in-bounds-p&svref\\cr aref&array-rank&upgraded-array-element-type\\cr array-dimension&array-rank-limit&upgraded-complex-part-type\\cr array-dimension-limit&array-row-major-index&vector\\cr array-dimensions&array-total-size&vector-pop\\cr array-displacement&array-total-size-limit&vector-push\\cr array-element-type&fill-pointer&vector-push-extend\\cr }$\\beginsubsubsection{Array Upgrading} \\DefineSection{ArrayUpgrading}$\\issue{ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS:UNIFY-UPGRADING}$ The \\newterm{upgraded array element type} of a \\term{type} T\\sub1 is a \\term{type} T\\sub2 that is a \\term{supertype} of T\\sub1 and that is used instead of T\\sub1 whenever T\\sub1 is used as an \\term{array element type} for object creation or type discrimination.$During creation of an \\term{array}, the \\term{element type} that was requested is called the \\newterm{expressed array element type}. The \\term{upgraded array element type} of the \\term{expressed array element type} becomes the \\newterm{actual array element type} of the \\term{array} that is created.$\\term{Type} \\term{upgrading} implies a movement upwards in the type hierarchy lattice. A \\term{type} is always a \\term{subtype} of its \\term{upgraded array element type}. Also, if a \\term{type} T\\sub x is a \\term{subtype} of another \\term{type} T\\sub y, then the \\term{upgraded array element type} of T\\sub x must be a \\term{subtype} of the \\term{upgraded array element type} of T\\sub y. Two \\term{disjoint} \\term{types} can be \\term{upgraded} to the same \\term{type}.$The \\term{upgraded array element type} T\\sub2 of a \\term{type} T\\sub1 is a function only of T\\sub1 itself; that is, it is independent of any other property of the \\term{array} for which T\\sub2 will be used, such as \\term{rank}, \\term{adjustability}, \\term{fill pointers}, or displacement. \\Thefunction{upgraded-array-element-type} can be used by \\term{conforming programs} to predict how the \\term{implementation} will \\term{upgrade} a given \\term{type}.$\\endissue{ARRAY-TYPE-ELEMENT-TYPE-SEMANTICS:UNIFY-UPGRADING}$\\endsubsubsection \\beginsubsubsection{Required Kinds of Specialized Arrays} \\DefineSection{RequiredSpecializedArrays}$\\term{Vectors} whose \\term{elements} are restricted to \\term{type} \\issue{CHARACTER-PROPOSAL:2-3-2} \\typeref{character} or a \\term{subtype} of \\typeref{character} \\endissue{CHARACTER-PROPOSAL:2-3-2} are called \\newtermidx{strings}{string}. \\term{Strings} are \\oftype{string}. \\Thenextfigure lists some \\term{defined names} related to \\term{strings}.$\\term{Strings} are \\term{specialized} \\term{arrays} and might logically have been included in this chapter. However, for purposes of readability most information about \\term{strings} does not appear in this chapter; see instead \\chapref \\Strings .$ \\displaythree{Operators that Manipulate Strings}{ char&string-equal&string-upcase\\cr make-string&string-greaterp&string{\\tt /=}\\cr nstring-capitalize&string-left-trim&string{\\tt <}\\cr nstring-downcase&string-lessp&string{\\tt <=}\\cr nstring-upcase&string-not-equal&string{\\tt =}\\cr schar&string-not-greaterp&string{\\tt >}\\cr string&string-not-lessp&string{\\tt >=}\\cr string-capitalize&string-right-trim&\\cr string-downcase&string-trim&\\cr }$\\term{Vectors} whose \\term{elements} are restricted to \\term{type} \\typeref{bit} are called \\newtermidx{bit vectors}{bit vector}. \\term{Bit vectors} are \\oftype{bit-vector}. \\Thenextfigure lists some \\term{defined names} for operations on \\term{bit arrays}.$\\displaythree{Operators that Manipulate Bit Arrays}{ bit&bit-ior&bit-orc2\\cr bit-and&bit-nand&bit-xor\\cr bit-andc1&bit-nor&sbit\\cr bit-andc2&bit-not&\\cr bit-eqv&bit-orc1&\\cr }$\\endsubsubsection \\endsubsection $" TEX-HTML-TEX-PARSING>