diff options
| author | Jay Belanger | 2004-11-22 04:53:51 +0000 |
|---|---|---|
| committer | Jay Belanger | 2004-11-22 04:53:51 +0000 |
| commit | 8cd2540e1759cfa456b28691dc096d283cddcd2f (patch) | |
| tree | 4fb213f3792e1c546986ca9a5346b91082eb6212 | |
| parent | c308c46341d93b2cb400fdaa714b1bf85d3a0a74 (diff) | |
| download | emacs-8cd2540e1759cfa456b28691dc096d283cddcd2f.tar.gz emacs-8cd2540e1759cfa456b28691dc096d283cddcd2f.zip | |
(math-read-big-lines): New variable.
(math-read-big-rec, math-read-big-char, math-read-big-emptyp)
(math-read-big-error, math-read-big-balance): Replace variable
lines by declared variable.
(math-read-big-baseline, math-read-big-h2): New variables.
(math-read-big-rec): Replace variables the-baseline and the-h2
by declared variables.
(math-read-big-rec): Fix typo.
(math-read-big-balance): Replace unbound variable by value.
(math-rb-h1, math-rb-h2, math-rb-v1, math-rb-v2): New variables.
(math-read-big-rec, math-read-big-char, math-read-big-emptyp)
(math-read-big-balance): Replace variables h1, h2, v1 and v2 by
declared variables.
(math-read-big-err-msg): New variable.
(math-read-big-error): Replace variable err-msg by declared variable.
| -rw-r--r-- | lisp/calc/calc-lang.el | 333 |
1 files changed, 188 insertions, 145 deletions
diff --git a/lisp/calc/calc-lang.el b/lisp/calc/calc-lang.el index ee00e022553..66a2fbe3276 100644 --- a/lisp/calc/calc-lang.el +++ b/lisp/calc/calc-lang.el | |||
| @@ -3,8 +3,7 @@ | |||
| 3 | ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: David Gillespie <daveg@synaptics.com> | 5 | ;; Author: David Gillespie <daveg@synaptics.com> |
| 6 | ;; Maintainers: D. Goel <deego@gnufans.org> | 6 | ;; Maintainer: Jay Belanger <belanger@truman.edu> |
| 7 | ;; Colin Walters <walters@debian.org> | ||
| 8 | 7 | ||
| 9 | ;; This file is part of GNU Emacs. | 8 | ;; This file is part of GNU Emacs. |
| 10 | 9 | ||
| @@ -708,134 +707,168 @@ | |||
| 708 | (list 'intv 3 x (math-read-expr-level (nth 3 op)))) | 707 | (list 'intv 3 x (math-read-expr-level (nth 3 op)))) |
| 709 | 708 | ||
| 710 | 709 | ||
| 711 | 710 | ;; The variable math-read-big-lines is local to math-read-big-expr in | |
| 712 | 711 | ;; calc-ext.el, but is used by math-read-big-rec, math-read-big-char, | |
| 713 | 712 | ;; math-read-big-emptyp, math-read-big-error and math-read-big-balance, | |
| 714 | (defun math-read-big-rec (h1 v1 h2 v2 &optional baseline prec short) | 713 | ;; which are called (directly and indirectly) by math-read-big-expr. |
| 714 | ;; It is also local to math-read-big-bigp in calc-ext.el, which calls | ||
| 715 | ;; math-read-big-balance. | ||
| 716 | (defvar math-read-big-lines) | ||
| 717 | |||
| 718 | ;; The variables math-read-big-baseline and math-read-big-h2 are | ||
| 719 | ;; local to math-read-big-expr in calc-ext.el, but used by | ||
| 720 | ;; math-read-big-rec. | ||
| 721 | (defvar math-read-big-baseline) | ||
| 722 | (defvar math-read-big-h2) | ||
| 723 | |||
| 724 | ;; The variables math-rb-h1, math-rb-h2, math-rb-v1 and math-rb-v2 | ||
| 725 | ;; are local to math-read-big-rec, but are used by math-read-big-char, | ||
| 726 | ;; math-read-big-emptyp and math-read-big-balance which are called by | ||
| 727 | ;; math-read-big-rec. | ||
| 728 | ;; math-rb-h2 is also local to math-read-big-bigp in calc-ext.el, | ||
| 729 | ;; which calls math-read-big-balance. | ||
| 730 | (defvar math-rb-h1) | ||
| 731 | (defvar math-rb-h2) | ||
| 732 | (defvar math-rb-v1) | ||
| 733 | (defvar math-rb-v2) | ||
| 734 | |||
| 735 | (defun math-read-big-rec (math-rb-h1 math-rb-v1 math-rb-h2 math-rb-v2 | ||
| 736 | &optional baseline prec short) | ||
| 715 | (or prec (setq prec 0)) | 737 | (or prec (setq prec 0)) |
| 716 | 738 | ||
| 717 | ;; Clip whitespace above or below. | 739 | ;; Clip whitespace above or below. |
| 718 | (while (and (< v1 v2) (math-read-big-emptyp h1 v1 h2 (1+ v1))) | 740 | (while (and (< math-rb-v1 math-rb-v2) |
| 719 | (setq v1 (1+ v1))) | 741 | (math-read-big-emptyp math-rb-h1 math-rb-v1 math-rb-h2 (1+ math-rb-v1))) |
| 720 | (while (and (< v1 v2) (math-read-big-emptyp h1 (1- v2) h2 v2)) | 742 | (setq math-rb-v1 (1+ math-rb-v1))) |
| 721 | (setq v2 (1- v2))) | 743 | (while (and (< math-rb-v1 math-rb-v2) |
| 744 | (math-read-big-emptyp math-rb-h1 (1- math-rb-v2) math-rb-h2 math-rb-v2)) | ||
| 745 | (setq math-rb-v2 (1- math-rb-v2))) | ||
| 722 | 746 | ||
| 723 | ;; If formula is a single line high, normal parser can handle it. | 747 | ;; If formula is a single line high, normal parser can handle it. |
| 724 | (if (<= v2 (1+ v1)) | 748 | (if (<= math-rb-v2 (1+ math-rb-v1)) |
| 725 | (if (or (<= v2 v1) | 749 | (if (or (<= math-rb-v2 math-rb-v1) |
| 726 | (> h1 (length (setq v2 (nth v1 lines))))) | 750 | (> math-rb-h1 (length (setq math-rb-v2 |
| 727 | (math-read-big-error h1 v1) | 751 | (nth math-rb-v1 math-read-big-lines))))) |
| 728 | (setq the-baseline v1 | 752 | (math-read-big-error math-rb-h1 math-rb-v1) |
| 729 | the-h2 h2 | 753 | (setq math-read-big-baseline math-rb-v1 |
| 730 | v2 (nth v1 lines) | 754 | math-read-big-h2 math-rb-h2 |
| 731 | h2 (math-read-expr (substring v2 h1 (min h2 (length v2))))) | 755 | math-rb-v2 (nth math-rb-v1 math-read-big-lines) |
| 732 | (if (eq (car-safe h2) 'error) | 756 | math-rb-h2 (math-read-expr |
| 733 | (math-read-big-error (+ h1 (nth 1 h2)) v1 (nth 2 h2)) | 757 | (substring math-rb-v2 math-rb-h1 |
| 734 | h2)) | 758 | (min math-rb-h2 (length math-rb-v2))))) |
| 759 | (if (eq (car-safe math-rb-h2) 'error) | ||
| 760 | (math-read-big-error (+ math-rb-h1 (nth 1 math-rb-h2)) | ||
| 761 | math-rb-v1 (nth 2 math-rb-h2)) | ||
| 762 | math-rb-h2)) | ||
| 735 | 763 | ||
| 736 | ;; Clip whitespace at left or right. | 764 | ;; Clip whitespace at left or right. |
| 737 | (while (and (< h1 h2) (math-read-big-emptyp h1 v1 (1+ h1) v2)) | 765 | (while (and (< math-rb-h1 math-rb-h2) |
| 738 | (setq h1 (1+ h1))) | 766 | (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) math-rb-v2)) |
| 739 | (while (and (< h1 h2) (math-read-big-emptyp (1- h2) v1 h2 v2)) | 767 | (setq math-rb-h1 (1+ math-rb-h1))) |
| 740 | (setq h2 (1- h2))) | 768 | (while (and (< math-rb-h1 math-rb-h2) |
| 769 | (math-read-big-emptyp (1- math-rb-h2) math-rb-v1 math-rb-h2 math-rb-v2)) | ||
| 770 | (setq math-rb-h2 (1- math-rb-h2))) | ||
| 741 | 771 | ||
| 742 | ;; Scan to find widest left-justified "----" in the region. | 772 | ;; Scan to find widest left-justified "----" in the region. |
| 743 | (let* ((widest nil) | 773 | (let* ((widest nil) |
| 744 | (widest-h2 0) | 774 | (widest-h2 0) |
| 745 | (lines-v1 (nthcdr v1 lines)) | 775 | (lines-v1 (nthcdr math-rb-v1 math-read-big-lines)) |
| 746 | (p lines-v1) | 776 | (p lines-v1) |
| 747 | (v v1) | 777 | (v math-rb-v1) |
| 748 | (other-v nil) | 778 | (other-v nil) |
| 749 | other-char line len h) | 779 | other-char line len h) |
| 750 | (while (< v v2) | 780 | (while (< v math-rb-v2) |
| 751 | (setq line (car p) | 781 | (setq line (car p) |
| 752 | len (min h2 (length line))) | 782 | len (min math-rb-h2 (length line))) |
| 753 | (and (< h1 len) | 783 | (and (< math-rb-h1 len) |
| 754 | (/= (aref line h1) ?\ ) | 784 | (/= (aref line math-rb-h1) ?\ ) |
| 755 | (if (and (= (aref line h1) ?\-) | 785 | (if (and (= (aref line math-rb-h1) ?\-) |
| 756 | ;; Make sure it's not a minus sign. | 786 | ;; Make sure it's not a minus sign. |
| 757 | (or (and (< (1+ h1) len) (= (aref line (1+ h1)) ?\-)) | 787 | (or (and (< (1+ math-rb-h1) len) |
| 758 | (/= (math-read-big-char h1 (1- v)) ?\ ) | 788 | (= (aref line (1+ math-rb-h1)) ?\-)) |
| 759 | (/= (math-read-big-char h1 (1+ v)) ?\ ))) | 789 | (/= (math-read-big-char math-rb-h1 (1- v)) ?\ ) |
| 790 | (/= (math-read-big-char math-rb-h1 (1+ v)) ?\ ))) | ||
| 760 | (progn | 791 | (progn |
| 761 | (setq h h1) | 792 | (setq h math-rb-h1) |
| 762 | (while (and (< (setq h (1+ h)) len) | 793 | (while (and (< (setq h (1+ h)) len) |
| 763 | (= (aref line h) ?\-))) | 794 | (= (aref line h) ?\-))) |
| 764 | (if (> h widest-h2) | 795 | (if (> h widest-h2) |
| 765 | (setq widest v | 796 | (setq widest v |
| 766 | widest-h2 h))) | 797 | widest-h2 h))) |
| 767 | (or other-v (setq other-v v other-char (aref line h1))))) | 798 | (or other-v (setq other-v v other-char (aref line math-rb-h1))))) |
| 768 | (setq v (1+ v) | 799 | (setq v (1+ v) |
| 769 | p (cdr p))) | 800 | p (cdr p))) |
| 770 | 801 | ||
| 771 | (cond ((not (setq v other-v)) | 802 | (cond ((not (setq v other-v)) |
| 772 | (math-read-big-error h1 v1)) ; Should never happen! | 803 | (math-read-big-error math-rb-h1 math-rb-v1)) ; Should never happen! |
| 773 | 804 | ||
| 774 | ;; Quotient. | 805 | ;; Quotient. |
| 775 | (widest | 806 | (widest |
| 776 | (setq h widest-h2 | 807 | (setq h widest-h2 |
| 777 | v widest) | 808 | v widest) |
| 778 | (let ((num (math-read-big-rec h1 v1 h v)) | 809 | (let ((num (math-read-big-rec math-rb-h1 math-rb-v1 h v)) |
| 779 | (den (math-read-big-rec h1 (1+ v) h v2))) | 810 | (den (math-read-big-rec math-rb-h1 (1+ v) h math-rb-v2))) |
| 780 | (setq p (if (and (math-integerp num) (math-integerp den)) | 811 | (setq p (if (and (math-integerp num) (math-integerp den)) |
| 781 | (math-make-frac num den) | 812 | (math-make-frac num den) |
| 782 | (list '/ num den))))) | 813 | (list '/ num den))))) |
| 783 | 814 | ||
| 784 | ;; Big radical sign. | 815 | ;; Big radical sign. |
| 785 | ((= other-char ?\\) | 816 | ((= other-char ?\\) |
| 786 | (or (= (math-read-big-char (1+ h1) v) ?\|) | 817 | (or (= (math-read-big-char (1+ math-rb-h1) v) ?\|) |
| 787 | (math-read-big-error (1+ h1) v "Malformed root sign")) | 818 | (math-read-big-error (1+ math-rb-h1) v "Malformed root sign")) |
| 788 | (math-read-big-emptyp h1 v1 (1+ h1) v nil t) | 819 | (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
| 789 | (while (= (math-read-big-char (1+ h1) (setq v (1- v))) ?\|)) | 820 | (while (= (math-read-big-char (1+ math-rb-h1) (setq v (1- v))) ?\|)) |
| 790 | (or (= (math-read-big-char (setq h (+ h1 2)) v) ?\_) | 821 | (or (= (math-read-big-char (setq h (+ math-rb-h1 2)) v) ?\_) |
| 791 | (math-read-big-error h v "Malformed root sign")) | 822 | (math-read-big-error h v "Malformed root sign")) |
| 792 | (while (= (math-read-big-char (setq h (1+ h)) v) ?\_)) | 823 | (while (= (math-read-big-char (setq h (1+ h)) v) ?\_)) |
| 793 | (math-read-big-emptyp h1 v1 (1+ h1) v nil t) | 824 | (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
| 794 | (math-read-big-emptyp h1 (1+ other-v) h v2 nil t) | 825 | (math-read-big-emptyp math-rb-h1 (1+ other-v) h math-rb-v2 nil t) |
| 795 | (setq p (list 'calcFunc-sqrt (math-read-big-rec | 826 | (setq p (list 'calcFunc-sqrt (math-read-big-rec |
| 796 | (+ h1 2) (1+ v) | 827 | (+ math-rb-h1 2) (1+ v) |
| 797 | h (1+ other-v) baseline)) | 828 | h (1+ other-v) baseline)) |
| 798 | v the-baseline)) | 829 | v math-read-big-baseline)) |
| 799 | 830 | ||
| 800 | ;; Small radical sign. | 831 | ;; Small radical sign. |
| 801 | ((and (= other-char ?V) | 832 | ((and (= other-char ?V) |
| 802 | (= (math-read-big-char (1+ h1) (1- v)) ?\_)) | 833 | (= (math-read-big-char (1+ math-rb-h1) (1- v)) ?\_)) |
| 803 | (setq h (1+ h1)) | 834 | (setq h (1+ math-rb-h1)) |
| 804 | (math-read-big-emptyp h1 v1 h (1- v) nil t) | 835 | (math-read-big-emptyp math-rb-h1 math-rb-v1 h (1- v) nil t) |
| 805 | (math-read-big-emptyp h1 (1+ v) h v2 nil t) | 836 | (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t) |
| 806 | (math-read-big-emptyp h1 v1 (1+ h1) v nil t) | 837 | (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
| 807 | (while (= (math-read-big-char (setq h (1+ h)) (1- v)) ?\_)) | 838 | (while (= (math-read-big-char (setq h (1+ h)) (1- v)) ?\_)) |
| 808 | (setq p (list 'calcFunc-sqrt (math-read-big-rec | 839 | (setq p (list 'calcFunc-sqrt (math-read-big-rec |
| 809 | (1+ h1) v h (1+ v) t)) | 840 | (1+ math-rb-h1) v h (1+ v) t)) |
| 810 | v the-baseline)) | 841 | v math-read-big-baseline)) |
| 811 | 842 | ||
| 812 | ;; Binomial coefficient. | 843 | ;; Binomial coefficient. |
| 813 | ((and (= other-char ?\() | 844 | ((and (= other-char ?\() |
| 814 | (= (math-read-big-char (1+ h1) v) ?\ ) | 845 | (= (math-read-big-char (1+ math-rb-h1) v) ?\ ) |
| 815 | (= (string-match "( *)" (nth v lines) h1) h1)) | 846 | (= (string-match "( *)" (nth v math-read-big-lines) |
| 847 | math-rb-h1) math-rb-h1)) | ||
| 816 | (setq h (match-end 0)) | 848 | (setq h (match-end 0)) |
| 817 | (math-read-big-emptyp h1 v1 (1+ h1) v nil t) | 849 | (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
| 818 | (math-read-big-emptyp h1 (1+ v) (1+ h1) v2 nil t) | 850 | (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t) |
| 819 | (math-read-big-emptyp (1- h) v1 h v nil t) | 851 | (math-read-big-emptyp (1- h) math-rb-v1 h v nil t) |
| 820 | (math-read-big-emptyp (1- h) (1+ v) h v2 nil t) | 852 | (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t) |
| 821 | (setq p (list 'calcFunc-choose | 853 | (setq p (list 'calcFunc-choose |
| 822 | (math-read-big-rec (1+ h1) v1 (1- h) v) | 854 | (math-read-big-rec (1+ math-rb-h1) math-rb-v1 (1- h) v) |
| 823 | (math-read-big-rec (1+ h1) (1+ v) | 855 | (math-read-big-rec (1+ math-rb-h1) (1+ v) |
| 824 | (1- h) v2)))) | 856 | (1- h) math-rb-v2)))) |
| 825 | 857 | ||
| 826 | ;; Minus sign. | 858 | ;; Minus sign. |
| 827 | ((= other-char ?\-) | 859 | ((= other-char ?\-) |
| 828 | (setq p (list 'neg (math-read-big-rec (1+ h1) v1 h2 v2 v 250 t)) | 860 | (setq p (list 'neg (math-read-big-rec (1+ math-rb-h1) math-rb-v1 |
| 829 | v the-baseline | 861 | math-rb-h2 math-rb-v2 v 250 t)) |
| 830 | h the-h2)) | 862 | v math-read-big-baseline |
| 863 | h math-read-big-h2)) | ||
| 831 | 864 | ||
| 832 | ;; Parentheses. | 865 | ;; Parentheses. |
| 833 | ((= other-char ?\() | 866 | ((= other-char ?\() |
| 834 | (math-read-big-emptyp h1 v1 (1+ h1) v nil t) | 867 | (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
| 835 | (math-read-big-emptyp h1 (1+ v) (1+ h1) v2 nil t) | 868 | (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t) |
| 836 | (setq h (math-read-big-balance (1+ h1) v "(" t)) | 869 | (setq h (math-read-big-balance (1+ math-rb-h1) v "(" t)) |
| 837 | (math-read-big-emptyp (1- h) v1 h v nil t) | 870 | (math-read-big-emptyp (1- h) math-rb-v1 h v nil t) |
| 838 | (math-read-big-emptyp (1- h) (1+ v) h v2 nil t) | 871 | (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t) |
| 839 | (let ((sep (math-read-big-char (1- h) v)) | 872 | (let ((sep (math-read-big-char (1- h) v)) |
| 840 | hmid) | 873 | hmid) |
| 841 | (if (= sep ?\.) | 874 | (if (= sep ?\.) |
| @@ -843,9 +876,11 @@ | |||
| 843 | (if (= sep ?\]) | 876 | (if (= sep ?\]) |
| 844 | (math-read-big-error (1- h) v "Expected `)'")) | 877 | (math-read-big-error (1- h) v "Expected `)'")) |
| 845 | (if (= sep ?\)) | 878 | (if (= sep ?\)) |
| 846 | (setq p (math-read-big-rec (1+ h1) v1 (1- h) v2 v)) | 879 | (setq p (math-read-big-rec |
| 880 | (1+ math-rb-h1) math-rb-v1 (1- h) math-rb-v2 v)) | ||
| 847 | (setq hmid (math-read-big-balance h v "(") | 881 | (setq hmid (math-read-big-balance h v "(") |
| 848 | p (list p (math-read-big-rec h v1 (1- hmid) v2 v)) | 882 | p (list p |
| 883 | (math-read-big-rec h math-rb-v1 (1- hmid) math-rb-v2 v)) | ||
| 849 | h hmid) | 884 | h hmid) |
| 850 | (cond ((= sep ?\.) | 885 | (cond ((= sep ?\.) |
| 851 | (setq p (cons 'intv (cons (if (= (math-read-big-char | 886 | (setq p (cons 'intv (cons (if (= (math-read-big-char |
| @@ -858,22 +893,22 @@ | |||
| 858 | ((= sep ?\,) | 893 | ((= sep ?\,) |
| 859 | (or (and (math-realp (car p)) (math-realp (nth 1 p))) | 894 | (or (and (math-realp (car p)) (math-realp (nth 1 p))) |
| 860 | (math-read-big-error | 895 | (math-read-big-error |
| 861 | h1 v "Complex components must be real")) | 896 | math-rb-h1 v "Complex components must be real")) |
| 862 | (setq p (cons 'cplx p))) | 897 | (setq p (cons 'cplx p))) |
| 863 | ((= sep ?\;) | 898 | ((= sep ?\;) |
| 864 | (or (and (math-realp (car p)) (math-anglep (nth 1 p))) | 899 | (or (and (math-realp (car p)) (math-anglep (nth 1 p))) |
| 865 | (math-read-big-error | 900 | (math-read-big-error |
| 866 | h1 v "Complex components must be real")) | 901 | math-rb-h1 v "Complex components must be real")) |
| 867 | (setq p (cons 'polar p))))))) | 902 | (setq p (cons 'polar p))))))) |
| 868 | 903 | ||
| 869 | ;; Matrix. | 904 | ;; Matrix. |
| 870 | ((and (= other-char ?\[) | 905 | ((and (= other-char ?\[) |
| 871 | (or (= (math-read-big-char (setq h h1) (1+ v)) ?\[) | 906 | (or (= (math-read-big-char (setq h math-rb-h1) (1+ v)) ?\[) |
| 872 | (= (math-read-big-char (setq h (1+ h)) v) ?\[) | 907 | (= (math-read-big-char (setq h (1+ h)) v) ?\[) |
| 873 | (and (= (math-read-big-char h v) ?\ ) | 908 | (and (= (math-read-big-char h v) ?\ ) |
| 874 | (= (math-read-big-char (setq h (1+ h)) v) ?\[))) | 909 | (= (math-read-big-char (setq h (1+ h)) v) ?\[))) |
| 875 | (= (math-read-big-char h (1+ v)) ?\[)) | 910 | (= (math-read-big-char h (1+ v)) ?\[)) |
| 876 | (math-read-big-emptyp h1 v1 h v nil t) | 911 | (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t) |
| 877 | (let ((vtop v) | 912 | (let ((vtop v) |
| 878 | (hleft h) | 913 | (hleft h) |
| 879 | (hright nil)) | 914 | (hright nil)) |
| @@ -889,7 +924,7 @@ | |||
| 889 | (and (memq (math-read-big-char h v) '(?\ ?\,)) | 924 | (and (memq (math-read-big-char h v) '(?\ ?\,)) |
| 890 | (= (math-read-big-char hleft (1+ v)) ?\[))) | 925 | (= (math-read-big-char hleft (1+ v)) ?\[))) |
| 891 | (setq v (1+ v))) | 926 | (setq v (1+ v))) |
| 892 | (or (= hleft h1) | 927 | (or (= hleft math-rb-h1) |
| 893 | (progn | 928 | (progn |
| 894 | (if (= (math-read-big-char h v) ?\ ) | 929 | (if (= (math-read-big-char h v) ?\ ) |
| 895 | (setq h (1+ h))) | 930 | (setq h (1+ h))) |
| @@ -898,22 +933,22 @@ | |||
| 898 | (math-read-big-error (1- h) v "Expected `]'")) | 933 | (math-read-big-error (1- h) v "Expected `]'")) |
| 899 | (if (= (math-read-big-char h vtop) ?\,) | 934 | (if (= (math-read-big-char h vtop) ?\,) |
| 900 | (setq h (1+ h))) | 935 | (setq h (1+ h))) |
| 901 | (math-read-big-emptyp h1 (1+ v) (1- h) v2 nil t) | 936 | (math-read-big-emptyp math-rb-h1 (1+ v) (1- h) math-rb-v2 nil t) |
| 902 | (setq v (+ vtop (/ (- v vtop) 2)) | 937 | (setq v (+ vtop (/ (- v vtop) 2)) |
| 903 | p (cons 'vec (nreverse p))))) | 938 | p (cons 'vec (nreverse p))))) |
| 904 | 939 | ||
| 905 | ;; Square brackets. | 940 | ;; Square brackets. |
| 906 | ((= other-char ?\[) | 941 | ((= other-char ?\[) |
| 907 | (math-read-big-emptyp h1 v1 (1+ h1) v nil t) | 942 | (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t) |
| 908 | (math-read-big-emptyp h1 (1+ v) (1+ h1) v2 nil t) | 943 | (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t) |
| 909 | (setq p nil | 944 | (setq p nil |
| 910 | h (1+ h1)) | 945 | h (1+ math-rb-h1)) |
| 911 | (while (progn | 946 | (while (progn |
| 912 | (setq widest (math-read-big-balance h v "[" t)) | 947 | (setq widest (math-read-big-balance h v "[" t)) |
| 913 | (math-read-big-emptyp (1- h) v1 h v nil t) | 948 | (math-read-big-emptyp (1- h) math-rb-v1 h v nil t) |
| 914 | (math-read-big-emptyp (1- h) (1+ v) h v2 nil t) | 949 | (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t) |
| 915 | (setq p (cons (math-read-big-rec | 950 | (setq p (cons (math-read-big-rec |
| 916 | h v1 (1- widest) v2 v) p) | 951 | h math-rb-v1 (1- widest) math-rb-v2 v) p) |
| 917 | h widest) | 952 | h widest) |
| 918 | (= (math-read-big-char (1- h) v) ?\,))) | 953 | (= (math-read-big-char (1- h) v) ?\,))) |
| 919 | (setq widest (math-read-big-char (1- h) v)) | 954 | (setq widest (math-read-big-char (1- h) v)) |
| @@ -923,8 +958,8 @@ | |||
| 923 | (if (= widest ?\.) | 958 | (if (= widest ?\.) |
| 924 | (setq h (1+ h) | 959 | (setq h (1+ h) |
| 925 | widest (math-read-big-balance h v "[") | 960 | widest (math-read-big-balance h v "[") |
| 926 | p (nconc p (list (math-read-big-big-rec | 961 | p (nconc p (list (math-read-big-rec |
| 927 | h v1 (1- widest) v2 v))) | 962 | h math-rb-v1 (1- widest) math-rb-v2 v))) |
| 928 | h widest | 963 | h widest |
| 929 | p (cons 'intv (cons (if (= (math-read-big-char (1- h) v) | 964 | p (cons 'intv (cons (if (= (math-read-big-char (1- h) v) |
| 930 | ?\]) | 965 | ?\]) |
| @@ -934,23 +969,23 @@ | |||
| 934 | 969 | ||
| 935 | ;; Date form. | 970 | ;; Date form. |
| 936 | ((= other-char ?\<) | 971 | ((= other-char ?\<) |
| 937 | (setq line (nth v lines)) | 972 | (setq line (nth v math-read-big-lines)) |
| 938 | (string-match ">" line h1) | 973 | (string-match ">" line math-rb-h1) |
| 939 | (setq h (match-end 0)) | 974 | (setq h (match-end 0)) |
| 940 | (math-read-big-emptyp h1 v1 h v nil t) | 975 | (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t) |
| 941 | (math-read-big-emptyp h1 (1+ v) h v2 nil t) | 976 | (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t) |
| 942 | (setq p (math-read-big-rec h1 v h (1+ v) v))) | 977 | (setq p (math-read-big-rec math-rb-h1 v h (1+ v) v))) |
| 943 | 978 | ||
| 944 | ;; Variable name or function call. | 979 | ;; Variable name or function call. |
| 945 | ((or (and (>= other-char ?a) (<= other-char ?z)) | 980 | ((or (and (>= other-char ?a) (<= other-char ?z)) |
| 946 | (and (>= other-char ?A) (<= other-char ?Z))) | 981 | (and (>= other-char ?A) (<= other-char ?Z))) |
| 947 | (setq line (nth v lines)) | 982 | (setq line (nth v math-read-big-lines)) |
| 948 | (string-match "\\([a-zA-Z'_]+\\) *" line h1) | 983 | (string-match "\\([a-zA-Z'_]+\\) *" line math-rb-h1) |
| 949 | (setq h (match-end 1) | 984 | (setq h (match-end 1) |
| 950 | widest (match-end 0) | 985 | widest (match-end 0) |
| 951 | p (math-match-substring line 1)) | 986 | p (math-match-substring line 1)) |
| 952 | (math-read-big-emptyp h1 v1 h v nil t) | 987 | (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t) |
| 953 | (math-read-big-emptyp h1 (1+ v) h v2 nil t) | 988 | (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t) |
| 954 | (if (= (math-read-big-char widest v) ?\() | 989 | (if (= (math-read-big-char widest v) ?\() |
| 955 | (progn | 990 | (progn |
| 956 | (setq line (if (string-match "-" p) | 991 | (setq line (if (string-match "-" p) |
| @@ -958,14 +993,14 @@ | |||
| 958 | (intern (concat "calcFunc-" p))) | 993 | (intern (concat "calcFunc-" p))) |
| 959 | h (1+ widest) | 994 | h (1+ widest) |
| 960 | p nil) | 995 | p nil) |
| 961 | (math-read-big-emptyp widest v1 h v nil t) | 996 | (math-read-big-emptyp widest math-rb-v1 h v nil t) |
| 962 | (math-read-big-emptyp widest (1+ v) h v2 nil t) | 997 | (math-read-big-emptyp widest (1+ v) h math-rb-v2 nil t) |
| 963 | (while (progn | 998 | (while (progn |
| 964 | (setq widest (math-read-big-balance h v "(" t)) | 999 | (setq widest (math-read-big-balance h v "(" t)) |
| 965 | (math-read-big-emptyp (1- h) v1 h v nil t) | 1000 | (math-read-big-emptyp (1- h) math-rb-v1 h v nil t) |
| 966 | (math-read-big-emptyp (1- h) (1+ v) h v2 nil t) | 1001 | (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t) |
| 967 | (setq p (cons (math-read-big-rec | 1002 | (setq p (cons (math-read-big-rec |
| 968 | h v1 (1- widest) v2 v) p) | 1003 | h math-rb-v1 (1- widest) math-rb-v2 v) p) |
| 969 | h widest) | 1004 | h widest) |
| 970 | (= (math-read-big-char (1- h) v) ?\,))) | 1005 | (= (math-read-big-char (1- h) v) ?\,))) |
| 971 | (or (= (math-read-big-char (1- h) v) ?\)) | 1006 | (or (= (math-read-big-char (1- h) v) ?\)) |
| @@ -979,44 +1014,45 @@ | |||
| 979 | 1014 | ||
| 980 | ;; Number. | 1015 | ;; Number. |
| 981 | (t | 1016 | (t |
| 982 | (setq line (nth v lines)) | 1017 | (setq line (nth v math-read-big-lines)) |
| 983 | (or (= (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\([0-9]+\\(#\\|\\^\\^\\)[0-9a-zA-Z:]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?" line h1) h1) | 1018 | (or (= (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\([0-9]+\\(#\\|\\^\\^\\)[0-9a-zA-Z:]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?" line math-rb-h1) math-rb-h1) |
| 984 | (math-read-big-error h v "Expected a number")) | 1019 | (math-read-big-error h v "Expected a number")) |
| 985 | (setq h (match-end 0) | 1020 | (setq h (match-end 0) |
| 986 | p (math-read-number (math-match-substring line 0))) | 1021 | p (math-read-number (math-match-substring line 0))) |
| 987 | (math-read-big-emptyp h1 v1 h v nil t) | 1022 | (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t) |
| 988 | (math-read-big-emptyp h1 (1+ v) h v2 nil t))) | 1023 | (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t))) |
| 989 | 1024 | ||
| 990 | ;; Now left term is bounded by h1, v1, h, v2; baseline = v. | 1025 | ;; Now left term is bounded by math-rb-h1, math-rb-v1, h, math-rb-v2; |
| 1026 | ;; baseline = v. | ||
| 991 | (if baseline | 1027 | (if baseline |
| 992 | (or (= v baseline) | 1028 | (or (= v baseline) |
| 993 | (math-read-big-error h1 v "Inconsistent baseline in formula")) | 1029 | (math-read-big-error math-rb-h1 v "Inconsistent baseline in formula")) |
| 994 | (setq baseline v)) | 1030 | (setq baseline v)) |
| 995 | 1031 | ||
| 996 | ;; Look for superscripts or subscripts. | 1032 | ;; Look for superscripts or subscripts. |
| 997 | (setq line (nth baseline lines) | 1033 | (setq line (nth baseline math-read-big-lines) |
| 998 | len (min h2 (length line)) | 1034 | len (min math-rb-h2 (length line)) |
| 999 | widest h) | 1035 | widest h) |
| 1000 | (while (and (< widest len) | 1036 | (while (and (< widest len) |
| 1001 | (= (aref line widest) ?\ )) | 1037 | (= (aref line widest) ?\ )) |
| 1002 | (setq widest (1+ widest))) | 1038 | (setq widest (1+ widest))) |
| 1003 | (and (>= widest len) (setq widest h2)) | 1039 | (and (>= widest len) (setq widest math-rb-h2)) |
| 1004 | (if (math-read-big-emptyp h v widest v2) | 1040 | (if (math-read-big-emptyp h v widest math-rb-v2) |
| 1005 | (if (math-read-big-emptyp h v1 widest v) | 1041 | (if (math-read-big-emptyp h math-rb-v1 widest v) |
| 1006 | (setq h widest) | 1042 | (setq h widest) |
| 1007 | (setq p (list '^ p (math-read-big-rec h v1 widest v)) | 1043 | (setq p (list '^ p (math-read-big-rec h math-rb-v1 widest v)) |
| 1008 | h widest)) | 1044 | h widest)) |
| 1009 | (if (math-read-big-emptyp h v1 widest v) | 1045 | (if (math-read-big-emptyp h math-rb-v1 widest v) |
| 1010 | (setq p (list 'calcFunc-subscr p | 1046 | (setq p (list 'calcFunc-subscr p |
| 1011 | (math-read-big-rec h v widest v2)) | 1047 | (math-read-big-rec h v widest math-rb-v2)) |
| 1012 | h widest))) | 1048 | h widest))) |
| 1013 | 1049 | ||
| 1014 | ;; Look for an operator name and grab additional terms. | 1050 | ;; Look for an operator name and grab additional terms. |
| 1015 | (while (and (< h len) | 1051 | (while (and (< h len) |
| 1016 | (if (setq widest (and (math-read-big-emptyp | 1052 | (if (setq widest (and (math-read-big-emptyp |
| 1017 | h v1 (1+ h) v) | 1053 | h math-rb-v1 (1+ h) v) |
| 1018 | (math-read-big-emptyp | 1054 | (math-read-big-emptyp |
| 1019 | h (1+ v) (1+ h) v2) | 1055 | h (1+ v) (1+ h) math-rb-v2) |
| 1020 | (string-match "<=\\|>=\\|\\+/-\\|!=\\|&&\\|||\\|:=\\|=>\\|." line h) | 1056 | (string-match "<=\\|>=\\|\\+/-\\|!=\\|&&\\|||\\|:=\\|=>\\|." line h) |
| 1021 | (assoc (math-match-substring line 0) | 1057 | (assoc (math-match-substring line 0) |
| 1022 | math-standard-opers))) | 1058 | math-standard-opers))) |
| @@ -1028,44 +1064,46 @@ | |||
| 1028 | (cond ((eq (nth 3 widest) -1) | 1064 | (cond ((eq (nth 3 widest) -1) |
| 1029 | (setq p (list (nth 1 widest) p))) | 1065 | (setq p (list (nth 1 widest) p))) |
| 1030 | ((equal (car widest) "?") | 1066 | ((equal (car widest) "?") |
| 1031 | (let ((y (math-read-big-rec h v1 h2 v2 baseline nil t))) | 1067 | (let ((y (math-read-big-rec h math-rb-v1 math-rb-h2 |
| 1032 | (or (= (math-read-big-char the-h2 baseline) ?\:) | 1068 | math-rb-v2 baseline nil t))) |
| 1033 | (math-read-big-error the-h2 baseline "Expected `:'")) | 1069 | (or (= (math-read-big-char math-read-big-h2 baseline) ?\:) |
| 1070 | (math-read-big-error math-read-big-h2 baseline "Expected `:'")) | ||
| 1034 | (setq p (list (nth 1 widest) p y | 1071 | (setq p (list (nth 1 widest) p y |
| 1035 | (math-read-big-rec (1+ the-h2) v1 h2 v2 | 1072 | (math-read-big-rec |
| 1036 | baseline (nth 3 widest) t)) | 1073 | (1+ math-read-big-h2) math-rb-v1 math-rb-h2 math-rb-v2 |
| 1037 | h the-h2))) | 1074 | baseline (nth 3 widest) t)) |
| 1075 | h math-read-big-h2))) | ||
| 1038 | (t | 1076 | (t |
| 1039 | (setq p (list (nth 1 widest) p | 1077 | (setq p (list (nth 1 widest) p |
| 1040 | (math-read-big-rec h v1 h2 v2 | 1078 | (math-read-big-rec h math-rb-v1 math-rb-h2 math-rb-v2 |
| 1041 | baseline (nth 3 widest) t)) | 1079 | baseline (nth 3 widest) t)) |
| 1042 | h the-h2)))) | 1080 | h math-read-big-h2)))) |
| 1043 | 1081 | ||
| 1044 | ;; Return all relevant information to caller. | 1082 | ;; Return all relevant information to caller. |
| 1045 | (setq the-baseline baseline | 1083 | (setq math-read-big-baseline baseline |
| 1046 | the-h2 h) | 1084 | math-read-big-h2 h) |
| 1047 | (or short (= the-h2 h2) | 1085 | (or short (= math-read-big-h2 math-rb-h2) |
| 1048 | (math-read-big-error h baseline)) | 1086 | (math-read-big-error h baseline)) |
| 1049 | p))) | 1087 | p))) |
| 1050 | 1088 | ||
| 1051 | (defun math-read-big-char (h v) | 1089 | (defun math-read-big-char (h v) |
| 1052 | (or (and (>= h h1) | 1090 | (or (and (>= h math-rb-h1) |
| 1053 | (< h h2) | 1091 | (< h math-rb-h2) |
| 1054 | (>= v v1) | 1092 | (>= v math-rb-v1) |
| 1055 | (< v v2) | 1093 | (< v math-rb-v2) |
| 1056 | (let ((line (nth v lines))) | 1094 | (let ((line (nth v math-read-big-lines))) |
| 1057 | (and line | 1095 | (and line |
| 1058 | (< h (length line)) | 1096 | (< h (length line)) |
| 1059 | (aref line h)))) | 1097 | (aref line h)))) |
| 1060 | ?\ )) | 1098 | ?\ )) |
| 1061 | 1099 | ||
| 1062 | (defun math-read-big-emptyp (eh1 ev1 eh2 ev2 &optional what error) | 1100 | (defun math-read-big-emptyp (eh1 ev1 eh2 ev2 &optional what error) |
| 1063 | (and (< ev1 v1) (setq ev1 v1)) | 1101 | (and (< ev1 math-rb-v1) (setq ev1 math-rb-v1)) |
| 1064 | (and (< eh1 h1) (setq eh1 h1)) | 1102 | (and (< eh1 math-rb-h1) (setq eh1 math-rb-h1)) |
| 1065 | (and (> ev2 v2) (setq ev2 v2)) | 1103 | (and (> ev2 math-rb-v2) (setq ev2 math-rb-v2)) |
| 1066 | (and (> eh2 h2) (setq eh2 h2)) | 1104 | (and (> eh2 math-rb-h2) (setq eh2 math-rb-h2)) |
| 1067 | (or what (setq what ?\ )) | 1105 | (or what (setq what ?\ )) |
| 1068 | (let ((p (nthcdr ev1 lines)) | 1106 | (let ((p (nthcdr ev1 math-read-big-lines)) |
| 1069 | h) | 1107 | h) |
| 1070 | (while (and (< ev1 ev2) | 1108 | (while (and (< ev1 ev2) |
| 1071 | (progn | 1109 | (progn |
| @@ -1081,25 +1119,30 @@ | |||
| 1081 | p (cdr p))) | 1119 | p (cdr p))) |
| 1082 | (>= ev1 ev2))) | 1120 | (>= ev1 ev2))) |
| 1083 | 1121 | ||
| 1122 | ;; math-read-big-err-msg is local to math-read-big-expr in calc-ext.el, | ||
| 1123 | ;; but is used by math-read-big-error which is called (indirectly) by | ||
| 1124 | ;; math-read-big-expr. | ||
| 1125 | (defvar math-read-big-err-msg) | ||
| 1126 | |||
| 1084 | (defun math-read-big-error (h v &optional msg) | 1127 | (defun math-read-big-error (h v &optional msg) |
| 1085 | (let ((pos 0) | 1128 | (let ((pos 0) |
| 1086 | (p lines)) | 1129 | (p math-read-big-lines)) |
| 1087 | (while (> v 0) | 1130 | (while (> v 0) |
| 1088 | (setq pos (+ pos 1 (length (car p))) | 1131 | (setq pos (+ pos 1 (length (car p))) |
| 1089 | p (cdr p) | 1132 | p (cdr p) |
| 1090 | v (1- v))) | 1133 | v (1- v))) |
| 1091 | (setq h (+ pos (min h (length (car p)))) | 1134 | (setq h (+ pos (min h (length (car p)))) |
| 1092 | err-msg (list 'error h (or msg "Syntax error"))) | 1135 | math-read-big-err-msg (list 'error h (or msg "Syntax error"))) |
| 1093 | (throw 'syntax nil))) | 1136 | (throw 'syntax nil))) |
| 1094 | 1137 | ||
| 1095 | (defun math-read-big-balance (h v what &optional commas) | 1138 | (defun math-read-big-balance (h v what &optional commas) |
| 1096 | (let* ((line (nth v lines)) | 1139 | (let* ((line (nth v math-read-big-lines)) |
| 1097 | (len (min h2 (length line))) | 1140 | (len (min math-rb-h2 (length line))) |
| 1098 | (count 1)) | 1141 | (count 1)) |
| 1099 | (while (> count 0) | 1142 | (while (> count 0) |
| 1100 | (if (>= h len) | 1143 | (if (>= h len) |
| 1101 | (if what | 1144 | (if what |
| 1102 | (math-read-big-error h1 v (format "Unmatched `%s'" what)) | 1145 | (math-read-big-error nil v (format "Unmatched `%s'" what)) |
| 1103 | (setq count 0)) | 1146 | (setq count 0)) |
| 1104 | (if (memq (aref line h) '(?\( ?\[)) | 1147 | (if (memq (aref line h) '(?\( ?\[)) |
| 1105 | (setq count (1+ count)) | 1148 | (setq count (1+ count)) |