From 146c9247eddf2b601a7e9e71c472912f5a7faf61 Mon Sep 17 00:00:00 2001 From: Teddy Date: Fri, 9 Aug 2013 19:34:13 +0800 Subject: str_to_lower should only apply to Symbols --- TODO.rst | 4 ++-- parser.cpp | 10 +++------- robust_test.scm | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/TODO.rst b/TODO.rst index 1a5df0e..99baab8 100644 --- a/TODO.rst +++ b/TODO.rst @@ -1,4 +1,4 @@ -- non-recursive equal? predicate -- ext_repr optimization +- Testing - Garbage Collection? +- ext_repr optimization - Add macro support diff --git a/parser.cpp b/parser.cpp index 7483847..a00f3f4 100644 --- a/parser.cpp +++ b/parser.cpp @@ -43,7 +43,7 @@ void Tokenizor::set_stream(FILE *_stream) { } while (0) #define TOP (*(buff_ptr - 1)) -void str_to_lower(string &str) { +string str_to_lower(string str) { size_t len = str.length(); for (size_t i = 0; i < len; i++) if ('A' <= str[i] && str[i] <= 'Z') @@ -112,11 +112,7 @@ bool Tokenizor::get_token(string &ret) { else *buff_ptr++ = ch; } - if (flag) - { - str_to_lower(ret); - return true; - } + if (flag) return true; } } if (buff_ptr != buff) POP; @@ -135,7 +131,7 @@ EvalObj *ASTGenerator::to_obj(const string &str) { if ((res = RealNumObj::from_string(str))) return res; if ((res = CompNumObj::from_string(str))) return res; if ((res = StrObj::from_string(str))) return res; - return new SymObj(str); // otherwise we assume it a symbol + return new SymObj(str_to_lower(str)); // otherwise we assume it a symbol } #define TO_EVAL(ptr) \ diff --git a/robust_test.scm b/robust_test.scm index 0e989b8..7b7bfd4 100644 --- a/robust_test.scm +++ b/robust_test.scm @@ -172,3 +172,49 @@ t src (eval src) (eval '(g 0)) + +(define f (lambda (x) (+ x x))) ;; test comments +((lambda (x y) (f 3)) 1 2) ;; first-class procedure +; this is a single line comment +; another line +(define f (lambda (x) (lambda (y) (+ x y)))) + +(f 1) ; # + +((f 1) 2) ; 3 + +(define g (lambda (x) (define y 2) (+ x y))) +(g 3) + +((lambda () (display 2) (display 1) (+ 1 2))) +(define g (lambda (x) (if (= x 5) 0 ((lambda () (display x) (g (+ x 1))))))) +(g 0) + +(define g (lambda (x) + (if (= x 5) + 0 + ((lambda () + (display x) + (g (+ x 1))))))) +(g 0) + +(define square (lambda (x) (* x x))) + +(square 2) + +(define (f x y) + ((lambda (a b) + (+ (* x (square a)) + (* y b) + (* a b))) + (+ 1 (* x y )) + (- 1 y))) + +(f 1 2) + +((lambda (x + y) (+ x y)) 4 / 2) ; a classic trick + +(if #t 1 ()) +(if #f 1 ()) ; Error +; "Test double quotes in comments" +(display " Test double quotes outside the comments ; ;; ; ; ") -- cgit v1.2.3