;;; *VERSION* ("1.3 28-jun-96") [PARAMETER] ;;; ;;; *PRINT-INFIX-COPYRIGHT* (t) [PARAMETER] ;;; If non-NIL, prints a copyright notice upon loading this file. ;;; ;;; INFIX-COPYRIGHT (&optional (stream *standard-output*)) [FUNCTION] ;;; Prints an INFIX copyright notice and header upon startup. ;;; ;;; *INFIX-READTABLE* ((copy-readtable nil)) [PARAMETER] ;;; ;;; *NORMAL-READTABLE* ((copy-readtable nil)) [PARAMETER] ;;; ;;; INFIX-ERROR (format-string &rest args) [MACRO] ;;; ;;; INFIX-READER (stream subchar arg) [FUNCTION] ;;; ;;; STRING->PREFIX (string) [FUNCTION] ;;; Convert a string to a prefix s-expression using the infix reader. ;;; If the argument is not a string, just return it as is. ;;; ;;; READ-INFIX (stream) [FUNCTION] ;;; ;;; READ-REGULAR (stream) [FUNCTION] ;;; ;;; SAME-OPERATOR-P (x y) [FUNCTION] ;;; ;;; SAME-TOKEN-P (x y) [FUNCTION] ;;; ;;; *PEEKED-TOKEN* (nil) [VARIABLE] ;;; ;;; READ-TOKEN (stream) [FUNCTION] ;;; ;;; PEEK-TOKEN (stream) [FUNCTION] ;;; ;;; FANCY-NUMBER-FORMAT-P (left operator stream) [FUNCTION] ;;; ;;; VALID-NUMBERP (string) [FUNCTION] ;;; ;;; GATHER-SUPERIORS (previous-operator stream) [FUNCTION] ;;; Gathers an expression whose operators all exceed the precedence of ;;; the operator to the left. ;;; ;;; GET-FIRST-TOKEN (stream) [FUNCTION] ;;; ;;; APPLY-TOKEN-PREFIX-OPERATOR (token stream) [FUNCTION] ;;; ;;; GET-NEXT-TOKEN (stream left) [FUNCTION] ;;; ;;; APPLY-TOKEN-INFIX-OPERATOR (token left stream) [FUNCTION] ;;; ;;; INFIX-READ-DELIMITED-LIST (end-token delimiter-token stream) [FUNCTION] ;;; ;;; *OPERATOR-ORDERING* ('(([ |(| !) (^) (~) (* / %) (+ -) (<< >>) [PARAMETER] ;;; (< == > <= != >=) (&) (^^) (|\||) (not) ;;; (and) (or) (= |:=| += -= *= /=) (|,|) (if) ;;; (then else) (] |)|) (%infix-end-token%))) ;;; Ordered list of operators of equal precedence. ;;; ;;; OPERATOR-LESSP (op1 op2) [FUNCTION] ;;; ;;; *RIGHT-ASSOCIATIVE-OPERATORS* ('(^ =)) [PARAMETER] ;;; ;;; OPERATOR-RIGHT-ASSOCIATIVE-P (operator) [FUNCTION] ;;; ;;; *TOKEN-OPERATORS* (nil) [VARIABLE] ;;; ;;; *TOKEN-PREFIX-OPERATOR-TABLE* ((make-hash-table)) [VARIABLE] ;;; ;;; *TOKEN-INFIX-OPERATOR-TABLE* ((make-hash-table)) [VARIABLE] ;;; ;;; TOKEN-OPERATOR-P (token) [FUNCTION] ;;; ;;; GET-TOKEN-PREFIX-OPERATOR (token) [FUNCTION] ;;; ;;; GET-TOKEN-INFIX-OPERATOR (token) [FUNCTION] ;;; ;;; DEFINE-TOKEN-OPERATOR (operator-name &key (prefix nil prefix-p) [MACRO] ;;; (infix nil infix-p)) ;;; ;;; DEFINE-CHARACTER-TOKENIZATION (char function) [MACRO] ;;; ;;; POST-PROCESS-EXPRESSION (expression) [FUNCTION] ;;; ;;; *TEST-CASES* ('(("1 * +2" (* 1 2)) ("1 * -2" (* 1 (- 2))) ("1 [PARAMETER] ;;; * /2" (* 1 (/ 2))) ("/2" (/ 2)) ("not true" ;;; (not true)) ("foo\\-bar" foo-bar) ("a + b-c" ;;; (+ a b (- c))) ("a + b\\-c" (+ a b-c)) ("f\\oo" ;;; |foo|) ;;; ("!foo-bar * 2" (* foo-bar 2)) ("!(foo bar baz)" ;;; (foo bar baz)) ("!foo-bar " foo-bar) ("!foo-bar" ;;; foo-bar) ;;; ("a+-b" (+ a (- b))) ("a+b" (+ a b)) ("a+b*c" (+ ;;; a (* b c))) ("a+b+c" (+ a b c)) ("a+b-c" (+ a b ;;; (- c))) ("a+b-c+d" (+ a b (- c) d)) ("a+b-c-d" (+ ;;; a b (- c) (- d))) ("a-b" (- a b)) ("a*b" (* a b)) ;;; ("a*b*c" (* a b c)) ("a*b+c" (+ (* a b) c)) ;;; ("a/b" (/ a b)) ("a^b" (expt a b)) ("foo/-bar" ;;; (/ foo (- bar))) ("1+2*3^4" (+ 1 ;;; (* 2 (expt 3 4)))) ("1+2*3^4+5" (+ 1 (* 2 ;;; (expt 3 4)) 5)) ("2*3^4+1" (+ (* 2 (expt 3 4)) ;;; 1)) ;;; ("2+3^4*5" (+ 2 (* (expt 3 4) 5))) ("2^3^4" (expt ;;; 2 (expt 3 4))) ("x^2 + y^2" (+ (expt x 2) ;;; (expt y 2))) ("(1+2)/3" (/ (+ 1 2) 3)) ("(a=b)" ;;; (setq a b)) ("(a=b,b=c)" ;;; (progn (setq a b) (setq b c))) ("1*(2+3)" (* 1 ;;; (+ 2 3))) ("1+2/3" (+ 1 (/ 2 3))) ("a,b" (progn a ;;; b)) ;;; ("a,b,c" (progn a b c)) ("foo(a,b,(c,d))" ;;; (foo a b (progn c d))) ("foo(a,b,c)" (foo a b c)) ;;; ("(a+b,c)" (progn (+ a b) c)) ("1" 1) ("-1" ;;; (- 1)) ("+1" 1) ("1." 1) ("1.1" 1.1) ("1e3" ;;; 1000.0) ;;; ("1e-3" 0.001) ("1f-3" 0.001) ("1e-3e" (- 1e 3e)) ;;; ("!1e-3 " 0.001) ("a and b and c" (and a b c)) ;;; ("a and b or c" (or (and a b) c)) ("a and b" (and ;;; a b)) ;;; ("a or b and c" (or a (and b c))) ("a or b" (or a ;;; b)) ;;; ("a>b" (ash a (- b))) ("~a" ;;; (lognot a)) ("a&&b" (and a b)) ("a||b" (or a b)) ;;; ("a%b" (mod a b)) ("x^2 ; the x coordinate + ;;; y^2 ; the y coordinate" :error) ;;; ("x^2 ; the x coordinate + y^2 ; the y ;;; coordinate " (+ (expt x 2) (expt y 2))) ;;; ("foo(bar,baz" :error) ("foo(bar,baz))" ;;; (foo bar baz)) ("foo[bar,baz]]" :error) ;;; ("[foo,bar]" :error) ("and a" :error) ;;; ("< a" :error) ("=bar" :error) ("*bar" :error) ;;; ("a not b" :error) ("a if b then c" :error) ;;; ("" :error) (")a" :error) ("]a" :error))) ;;; ;;; TEST-INFIX (&optional (tests *test-cases*)) [FUNCTION] ;;; ;;; TEST-INFIX-CASE (string result) [FUNCTION] ;;;