Permalink
Browse files

really big integers exposed stack overflow bugs in number scanner; fi…

…xed by switching from recursive to iterative
  • Loading branch information...
1 parent 89d966b commit 87c49caa9f70273027a440e609d8d4dc7beb0efc @cormullion committed Jan 7, 2014
Showing with 22 additions and 11 deletions.
  1. +16 −3 newlisp-parser-test.lsp
  2. +6 −8 newlisp-parser.lsp
View
@@ -42,13 +42,26 @@
; unicode
(test {unicode } {{\unnnn} (utf8len "我能吞下玻璃而不伤身体。")} 'display)
-; try parsing some smallish files
+; try parsing smaller files
(test {this parser script } (read-file (string (env {HOME}) {/projects/programming/newlisp-projects/newlisp-parser.lsp})))
+
;(test {markdown } (read-file (string (env {HOME}) {/projects/programming/newlisp-projects/markdown.lsp})))
+
;(test {life } (read-file (string (env {HOME}) {/projects/programming/newlisp-projects/life.lsp})))
-; try parsing bigger files takes too long
-;(test {qa} (read-file (string (env {HOME}) {/projects/programming/newlisp-working/newlisp-10.3.2/qa-specific-tests/qa-bench})))
+; bigger files can take some time
+;(test {qa-bench} (read-file (string (env {HOME})
+ {/Downloads/newlisp-10.5.7/qa-specific-tests/qa-bench})))
+
+; test all qa files in newLISP distribution
+
+(map
+ (fn (file)
+ (println { processing } file)
+ (if-not (catch (test {batch} (read-file (string (env {HOME}) {/Downloads/newlisp-10.5.7/qa-specific-tests/} file))) 'error)
+ (println " failed " file " " error)))
+ (directory
+ (string (env {HOME}) {/Downloads/newlisp-10.5.7/qa-specific-tests/}) {qa*}))
(println "\n" {all tests completed})
View
@@ -4,7 +4,7 @@
;; @author cormullion
;; @description newLISP source code lexer/tokenizer/parser
;; @location somewhere on github
-;; @version 0.2 of 2014-01-05 17:30:10 (bigint handling added)
+;; @version 0.2 of 2014-01-07 11:19:45 bugs in bigint
;;<h4>About this module</h4>
;;<p>The Nlex module is a lexer/tokenizer/parser for newLISP source code.
;; An expert from StackOverflow xplains:
@@ -81,12 +81,10 @@
(add-to-parse-tree (list 'Symbol res))))
(define (read-number-scanner list-so-far)
- (let ((next-char (peek-char)))
- ;; if next-char is a digit then recurse
- (if (and (char-numeric? next-char) next-char)
- (read-number-scanner (cons (get-next-char) list-so-far))
- (reverse list-so-far))))
-
+ (while (char-numeric? (peek-char))
+ (push (get-next-char) list-so-far -1))
+ list-so-far)
+
(define (precise-float str)
; more faithful to original format than newLISP's float?
(let ((p "") (q ""))
@@ -122,7 +120,7 @@
(empty? (difference (explode number-as-string) (explode "01234567"))))
(set 'res (list 'Octal number-as-string)))
; implicit bignum, interpreted by newLISP as a bigint
- ((> (abs (bigint number-as-string) 9223372036854775807))
+ ((> (abs (bigint number-as-string)) 9223372036854775807)
(set 'res (list 'Bigint (bigint number-as-string))))
; perhaps an integer? 019 is read as 19 ...
((integer? (int number-as-string 0 10))

0 comments on commit 87c49ca

Please sign in to comment.