Skip to content

Commit

Permalink
really big integers exposed stack overflow bugs in number scanner; fi…
Browse files Browse the repository at this point in the history
…xed by switching from recursive to iterative
  • Loading branch information
cormullion committed Jan 7, 2014
1 parent 89d966b commit 87c49ca
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
19 changes: 16 additions & 3 deletions newlisp-parser-test.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
14 changes: 6 additions & 8 deletions newlisp-parser.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 ""))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 87c49ca

Please sign in to comment.