aboutsummaryrefslogtreecommitdiff
path: root/src/interp
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2009-01-15 02:01:28 +0000
committerdos-reis <gdr@axiomatics.org>2009-01-15 02:01:28 +0000
commit7b3a06b249e272857c858c6ab7ab37c8f1e128e1 (patch)
tree3ac06b7857e9283fb9d62950121b4818f931544a /src/interp
parent839f230416f2e0c5d8efcf778edeee3a31ac8f7b (diff)
downloadopen-axiom-7b3a06b249e272857c858c6ab7ab37c8f1e128e1.tar.gz
* algebra/riccati.spad.pamphlet (innerlb$PrimitiveRatRicDE): Fix
thinko. * interp/bootlex.lisp (get-decimal-number-token): New. (get-integer-in-radix): Likewise. (is-radix-char): Likewise. (get-spad-integer-token): Likewise. Use them. (get-BOOT-token): Use it. * interp/metalex.lisp: Tidy.
Diffstat (limited to 'src/interp')
-rw-r--r--src/interp/bootlex.lisp56
-rw-r--r--src/interp/metalex.lisp17
2 files changed, 62 insertions, 11 deletions
diff --git a/src/interp/bootlex.lisp b/src/interp/bootlex.lisp
index 1afad6e7..4cd605d5 100644
--- a/src/interp/bootlex.lisp
+++ b/src/interp/bootlex.lisp
@@ -1,6 +1,6 @@
;; Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
;; All rights reserved.
-;; Copyright (C) 2007-2008, Gabriel Dos Reis.
+;; Copyright (C) 2007-2009, Gabriel Dos Reis.
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
@@ -194,7 +194,7 @@ Otherwise, get a .. identifier."
(get-boot-identifier-token token t))
(argument-designator (get-argument-designator-token token))
(id (get-boot-identifier-token token))
- (num (get-number-token token))
+ (num (get-spad-integer-token token))
(string (get-SPADSTRING-token token))
(special-char (get-special-token token))
(t (get-gliph-token token token-type))))))
@@ -303,6 +303,56 @@ or the chracters ?, !, ' or %"
(return (token-install (copy-seq buf) ;should make a simple string
'spadstring token))))
+;; -*- Parse an integer number -*-
+;; The number may be written in plain format, where the radix
+;; is implicitly taken to be 10. Or the spelling can explicitly
+;; specify a radix. That radix can be anything in the range 2..36
+
+;; Subroutine GET-NUMBER-TOKEN-MAYBE-WITH-RADIX.
+;; Read a the characters of a decimal integer and returns its
+;; value.
+(defun get-decimal-number-token (buf)
+ (tagbody lp
+ (suffix (current-char) buf)
+ (let ((next-chr (next-char)))
+ (cond ((digitp next-chr)
+ (advance-char)
+ (go lp)))))
+ (parse-integer buf))
+
+;; Subroutine of GET-NUMBER-TOKEN-MAYBE-WITH-RADIX.
+;; We just read the radix of an integer number; parse the
+;; digits forming that integer token.
+(defun get-integer-in-radix (buf r)
+ (unless (> r 1)
+ (meta-syntax-error))
+ (let ((mark (1+ (size buf))))
+ (tagbody lp
+ (suffix (current-char) buf)
+ (let* ((nxt (next-char))
+ (dig (|rdigit?| nxt)))
+ (when dig
+ (unless (< dig r)
+ (meta-syntax-error))
+ (advance-char)
+ (go lp))))
+ (parse-integer buf :start mark :radix r)))
+
+(defun is-radix-char (c)
+ (or (eql c #\r)
+ (eql c #\R)))
+
+;; Parse an integer token, written either implicitly in decimal form,
+;; or explicitly specified radix.
+(defun get-spad-integer-token (token)
+ (let* ((buf (make-adjustable-string 0))
+ (val (get-decimal-number-token buf)))
+ (advance-char)
+ (when (is-radix-char (current-char))
+ (setq val (get-integer-in-radix buf val))
+ (advance-char))
+ (token-install val 'number token (size buf))))
+
; **** 4. BOOT token parsing actions
@@ -342,5 +392,5 @@ or the chracters ?, !, ' or %"
(defun SPAD_SHORT_ERROR () (current-line-show))
(defun SPAD_ERROR_LOC (STR)
- (format str "******** Boot Syntax Error detected ********"))
+ (format str "******** Spad Syntax Error detected ********"))
diff --git a/src/interp/metalex.lisp b/src/interp/metalex.lisp
index cc8189c6..5a4d718d 100644
--- a/src/interp/metalex.lisp
+++ b/src/interp/metalex.lisp
@@ -1,6 +1,6 @@
;; Copyright (c) 1991-2002, The Numerical Algorithms Group Ltd.
;; All rights reserved.
-;; Copyright (C) 2007-2008, Gabriel Dos Reis.
+;; Copyright (C) 2007-2009, Gabriel Dos Reis.
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
@@ -305,7 +305,8 @@ NonBlank is true if the token is not preceded by a blank."
(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 (token-type token) type
+ (setf (token-symbol token) symbol
+ (token-type token) type
(token-nonblank token) nonblank)
token)
@@ -752,17 +753,17 @@ special character be the atom whose print name is the character itself."
(defun get-number-token (token)
"Take a number off the input stream."
(prog ((buf (make-adjustable-string 0)))
- nu1 (suffix (current-char) buf) ; Integer part
+ nu1
+ (suffix (current-char) buf) ; Integer part
(let ((next-chr (next-char)))
(cond ((digitp next-chr)
(advance-char)
(go nu1))))
(advance-char)
- formint(return (token-install
- (read-from-string buf)
- 'number token
- (size buf) ;used to keep track of digit count
- ))))
+ (return (token-install (read-from-string buf)
+ 'number token
+ (size buf) ;used to keep track of digit count
+ ))))
; *** 4. META Auxiliary Parsing Actions