* lisp/calc/calc.el: Silence byte-compiler warnings
[emacs.git] / lisp / calc / calc-aent.el
blobf4754c73e7e70a86539ddeb16ecd17fd096dbdda
1 ;;; calc-aent.el --- algebraic entry functions for Calc
3 ;; Copyright (C) 1990-1993, 2001-2015 Free Software Foundation, Inc.
5 ;; Author: Dave Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 ;; This file is autoloaded from calc.el.
29 (require 'calc)
30 (require 'calc-macs)
32 ;; Declare functions which are defined elsewhere.
33 (declare-function calc-digit-start-entry "calc" ())
34 (declare-function calc-refresh-evaltos "calc-ext" (&optional which-var))
35 (declare-function calc-execute-kbd-macro "calc-prog" (mac arg &rest prefix))
36 (declare-function math-is-true "calc-ext" (expr))
37 (declare-function calc-explain-why "calc-stuff" (why &optional more))
38 (declare-function calc-alg-edit "calc-yank" (str))
39 (declare-function math-composite-inequalities "calc-prog" (x op))
40 (declare-function math-flatten-lands "calc-rewr" (expr))
41 (declare-function math-multi-subst "calc-map" (expr olds news))
42 (declare-function calcFunc-vmatches "calc-rewr" (expr pat))
43 (declare-function math-simplify "calc-alg" (top-expr))
44 (declare-function math-known-matrixp "calc-arith" (a))
45 (declare-function math-parse-fortran-subscr "calc-lang" (sym args))
46 (declare-function math-to-radians-2 "calc-math" (a &optional force-symbolic))
47 (declare-function math-read-string "calc-ext" ())
48 (declare-function math-read-brackets "calc-vec" (space-sep math-rb-close))
49 (declare-function math-read-angle-brackets "calc-forms" ())
50 (declare-function math-to-percentsigns "calccomp" (x))
52 (defvar calc-quick-calc-history nil
53 "The history list for quick-calc.")
55 ;;;###autoload
56 (defun calc-do-quick-calc (&optional insert)
57 (require 'calc-ext)
58 (calc-check-defines)
59 (if (eq major-mode 'calc-mode)
60 (calc-algebraic-entry t)
61 (let (buf shortbuf)
62 (save-excursion
63 (calc-create-buffer)
64 (let* ((calc-command-flags nil)
65 (calc-dollar-values calc-quick-prev-results)
66 (calc-dollar-used 0)
67 (enable-recursive-minibuffers t)
68 (calc-language (if (memq calc-language '(nil big))
69 'flat calc-language))
70 (entry (calc-do-alg-entry "" "Quick calc: " t 'calc-quick-calc-history))
71 (alg-exp (mapcar 'math-evaluate-expr entry)))
72 (when (and (= (length alg-exp) 1)
73 (eq (car-safe (car alg-exp)) 'calcFunc-assign)
74 (= (length (car alg-exp)) 3)
75 (eq (car-safe (nth 1 (car alg-exp))) 'var))
76 (set (nth 2 (nth 1 (car alg-exp))) (nth 2 (car alg-exp)))
77 (calc-refresh-evaltos (nth 2 (nth 1 (car alg-exp))))
78 (setq alg-exp (list (nth 2 (car alg-exp)))))
79 (setq calc-quick-prev-results alg-exp
80 buf (mapconcat (function (lambda (x)
81 (math-format-value x 1000)))
82 alg-exp
83 " ")
84 shortbuf buf)
85 (if (and (= (length alg-exp) 1)
86 (memq (car-safe (car alg-exp)) '(nil bigpos bigneg))
87 (< (length buf) 20)
88 (= calc-number-radix 10))
89 (setq buf (concat buf " ("
90 (let ((calc-number-radix 16))
91 (math-format-value (car alg-exp) 1000))
92 ", "
93 (let ((calc-number-radix 8))
94 (math-format-value (car alg-exp) 1000))
95 ", "
96 (let ((calc-number-radix 2))
97 (math-format-value (car alg-exp) 1000))
98 (if (and (integerp (car alg-exp))
99 (> (car alg-exp) 0)
100 (< (car alg-exp) 127))
101 (format ", \"%c\"" (car alg-exp))
103 ")")))
104 (if (and (< (length buf) (frame-width)) (= (length entry) 1)
105 (featurep 'calc-ext))
106 (let ((long (concat (math-format-value (car entry) 1000)
107 " => " buf)))
108 (if (<= (length long) (- (frame-width) 8))
109 (setq buf long))))
110 (calc-handle-whys)
111 (message "Result: %s" buf)))
112 (if (or insert
113 (eq last-command-event 10))
114 (insert shortbuf)
115 (kill-new shortbuf)))))
117 ;;;###autoload
118 (defun calc-do-calc-eval (str separator args)
119 (calc-check-defines)
120 (catch 'calc-error
121 (save-excursion
122 (calc-create-buffer)
123 (cond
124 ((and (consp str) (not (symbolp (car str))))
125 (let ((calc-language nil)
126 (math-expr-opers (math-standard-ops))
127 (calc-internal-prec 12)
128 (calc-word-size 32)
129 (calc-symbolic-mode nil)
130 (calc-matrix-mode nil)
131 (calc-angle-mode 'deg)
132 (calc-number-radix 10)
133 (calc-twos-complement-mode nil)
134 (calc-leading-zeros nil)
135 (calc-group-digits nil)
136 (calc-point-char ".")
137 (calc-frac-format '(":" nil))
138 (calc-prefer-frac nil)
139 (calc-hms-format "%s@ %s' %s\"")
140 (calc-date-format '((H ":" mm C SS pp " ")
141 Www " " Mmm " " D ", " YYYY))
142 (calc-float-format '(float 0))
143 (calc-full-float-format '(float 0))
144 (calc-complex-format nil)
145 (calc-matrix-just nil)
146 (calc-full-vectors t)
147 (calc-break-vectors nil)
148 (calc-vector-commas ",")
149 (calc-vector-brackets "[]")
150 (calc-matrix-brackets '(R O))
151 (calc-complex-mode 'cplx)
152 (calc-infinite-mode nil)
153 (calc-display-strings nil)
154 (calc-simplify-mode nil)
155 (calc-display-working-message 'lots)
156 (strp (cdr str)))
157 (while strp
158 (set (car strp) (nth 1 strp))
159 (setq strp (cdr (cdr strp))))
160 (calc-do-calc-eval (car str) separator args)))
161 ((eq separator 'eval)
162 (eval str))
163 ((eq separator 'macro)
164 (require 'calc-ext)
165 (let* ((calc-buffer (current-buffer))
166 (calc-window (get-buffer-window calc-buffer))
167 (save-window (selected-window)))
168 (if calc-window
169 (unwind-protect
170 (progn
171 (select-window calc-window)
172 (calc-execute-kbd-macro str nil (car args)))
173 (and (window-point save-window)
174 (select-window save-window)))
175 (save-window-excursion
176 (select-window (get-largest-window))
177 (switch-to-buffer calc-buffer)
178 (calc-execute-kbd-macro str nil (car args)))))
179 nil)
180 ((eq separator 'pop)
181 (or (not (integerp str))
182 (= str 0)
183 (calc-pop (min str (calc-stack-size))))
184 (calc-stack-size))
185 ((eq separator 'top)
186 (and (integerp str)
187 (> str 0)
188 (<= str (calc-stack-size))
189 (math-format-value (calc-top-n str (car args)) 1000)))
190 ((eq separator 'rawtop)
191 (and (integerp str)
192 (> str 0)
193 (<= str (calc-stack-size))
194 (calc-top-n str (car args))))
196 (let* ((calc-command-flags nil)
197 (calc-next-why nil)
198 (calc-language (if (memq calc-language '(nil big))
199 'flat calc-language))
200 (calc-dollar-values (mapcar
201 (function
202 (lambda (x)
203 (if (stringp x)
204 (progn
205 (setq x (math-read-exprs x))
206 (if (eq (car-safe x)
207 'error)
208 (throw 'calc-error
209 (calc-eval-error
210 (cdr x)))
211 (car x)))
212 x)))
213 args))
214 (calc-dollar-used 0)
215 (res (if (stringp str)
216 (math-read-exprs str)
217 (list str)))
218 buf)
219 (if (eq (car res) 'error)
220 (calc-eval-error (cdr res))
221 (setq res (mapcar 'calc-normalize res))
222 (and (memq 'clear-message calc-command-flags)
223 (message ""))
224 (cond ((eq separator 'pred)
225 (require 'calc-ext)
226 (if (= (length res) 1)
227 (math-is-true (car res))
228 (calc-eval-error '(0 "Single value expected"))))
229 ((eq separator 'raw)
230 (if (= (length res) 1)
231 (car res)
232 (calc-eval-error '(0 "Single value expected"))))
233 ((eq separator 'list)
234 res)
235 ((memq separator '(num rawnum))
236 (if (= (length res) 1)
237 (if (math-constp (car res))
238 (if (eq separator 'num)
239 (math-format-value (car res) 1000)
240 (car res))
241 (calc-eval-error
242 (list 0
243 (if calc-next-why
244 (calc-explain-why (car calc-next-why))
245 "Number expected"))))
246 (calc-eval-error '(0 "Single value expected"))))
247 ((eq separator 'push)
248 (calc-push-list res)
249 nil)
250 (t (while res
251 (setq buf (concat buf
252 (and buf (or separator ", "))
253 (math-format-value (car res) 1000))
254 res (cdr res)))
255 buf)))))))))
257 (defvar calc-eval-error nil
258 "Determines how calc handles errors.
259 If nil, return a list containing the character position of error.
260 STRING means return error message as string rather than list.
261 The value t means abort and give an error message.")
263 (defun calc-eval-error (msg)
264 (if calc-eval-error
265 (if (eq calc-eval-error 'string)
266 (nth 1 msg)
267 (error "%s" (nth 1 msg)))
268 msg))
271 ;;;; Reading an expression in algebraic form.
273 ;;;###autoload
274 (defun calc-auto-algebraic-entry (&optional prefix)
275 (interactive "P")
276 (calc-algebraic-entry prefix t))
278 ;;;###autoload
279 (defun calc-algebraic-entry (&optional prefix auto)
280 (interactive "P")
281 (calc-wrapper
282 (let ((calc-language (if prefix nil calc-language))
283 (math-expr-opers (if prefix (math-standard-ops) (math-expr-ops))))
284 (calc-alg-entry (and auto (char-to-string last-command-event))))))
286 (defvar calc-alg-entry-history nil
287 "History for algebraic entry.")
289 ;;;###autoload
290 (defun calc-alg-entry (&optional initial prompt)
291 (let* ((calc-dollar-values (mapcar #'calc-get-stack-element
292 (nthcdr calc-stack-top calc-stack)))
293 (calc-dollar-used 0)
294 (calc-plain-entry t)
295 (alg-exp (calc-do-alg-entry initial prompt t 'calc-alg-entry-history)))
296 (if (stringp alg-exp)
297 (progn
298 (require 'calc-ext)
299 (calc-alg-edit alg-exp))
300 (let* ((calc-simplify-mode (if (eq last-command-event ?\C-j)
301 'none
302 calc-simplify-mode))
303 (nvals (mapcar 'calc-normalize alg-exp)))
304 (while alg-exp
305 (calc-record (if (featurep 'calc-ext) (car alg-exp) (car nvals))
306 "alg'")
307 (calc-pop-push-record-list calc-dollar-used
308 (and (not (equal (car alg-exp)
309 (car nvals)))
310 (featurep 'calc-ext)
312 (list (car nvals)))
313 (setq alg-exp (cdr alg-exp)
314 nvals (cdr nvals)
315 calc-dollar-used 0)))
316 (calc-handle-whys))))
318 (defvar calc-alg-ent-map
319 (let ((map (make-sparse-keymap)))
320 (set-keymap-parent map minibuffer-local-map)
321 (define-key map "'" 'calcAlg-previous)
322 (define-key map "`" 'calcAlg-edit)
323 (define-key map "\C-m" 'calcAlg-enter)
324 (define-key map "\C-j" 'calcAlg-enter)
325 map)
326 "The keymap used for algebraic entry.")
328 (defvar calc-alg-ent-esc-map
329 (let ((map (make-keymap))
330 (i 33))
331 (set-keymap-parent map esc-map)
332 (while (< i 127)
333 (define-key map (vector i) 'calcAlg-escape)
334 (setq i (1+ i)))
335 map)
336 "The keymap used for escapes in algebraic entry.")
338 (defvar calc-alg-exp)
340 ;;;###autoload
341 (defun calc-do-alg-entry (&optional initial prompt no-normalize history)
342 (let* ((calc-buffer (current-buffer))
343 (blink-matching-check-function 'calcAlg-blink-matching-check)
344 (calc-alg-exp 'error))
345 (define-key calc-alg-ent-map "\e" nil)
346 (if (eq calc-algebraic-mode 'total)
347 (define-key calc-alg-ent-map "\e" calc-alg-ent-esc-map)
348 (define-key calc-alg-ent-map "\e+" 'calcAlg-plus-minus)
349 (define-key calc-alg-ent-map "\em" 'calcAlg-mod)
350 (define-key calc-alg-ent-map "\e=" 'calcAlg-equals)
351 (define-key calc-alg-ent-map "\e\r" 'calcAlg-equals)
352 (define-key calc-alg-ent-map "\ep" 'previous-history-element)
353 (define-key calc-alg-ent-map "\en" 'next-history-element)
354 (define-key calc-alg-ent-map "\e%" 'self-insert-command))
355 (setq calc-aborted-prefix nil)
356 (let ((buf (read-from-minibuffer (or prompt "Algebraic: ")
357 (or initial "")
358 calc-alg-ent-map nil history)))
359 (when (eq calc-alg-exp 'error)
360 (when (eq (car-safe (setq calc-alg-exp (math-read-exprs buf))) 'error)
361 (setq calc-alg-exp nil)))
362 (setq calc-aborted-prefix "alg'")
363 (or no-normalize
364 (and calc-alg-exp (setq calc-alg-exp (mapcar 'calc-normalize calc-alg-exp))))
365 calc-alg-exp)))
367 (defun calcAlg-plus-minus ()
368 (interactive)
369 (if (calc-minibuffer-contains ".* \\'")
370 (insert "+/- ")
371 (insert " +/- ")))
373 (defun calcAlg-mod ()
374 (interactive)
375 (if (not (calc-minibuffer-contains ".* \\'"))
376 (insert " "))
377 (if (calc-minibuffer-contains ".* mod +\\'")
378 (if calc-previous-modulo
379 (insert (math-format-flat-expr calc-previous-modulo 0))
380 (beep))
381 (insert "mod ")))
383 (defun calcAlg-previous ()
384 (interactive)
385 (if (calc-minibuffer-contains "\\'")
386 (previous-history-element 1)
387 (insert "'")))
389 (defun calcAlg-equals ()
390 (interactive)
391 (unwind-protect
392 (calcAlg-enter)
393 (if (consp calc-alg-exp)
394 (progn (setq prefix-arg (length calc-alg-exp))
395 (calc-unread-command ?=)))))
397 (defun calcAlg-escape ()
398 (interactive)
399 (calc-unread-command)
400 (save-excursion
401 (calc-select-buffer)
402 (use-local-map calc-mode-map))
403 (calcAlg-enter))
405 (defvar calc-plain-entry nil)
406 (defun calcAlg-edit ()
407 (interactive)
408 (if (or (not calc-plain-entry)
409 (calc-minibuffer-contains
410 "\\`\\([^\"]*\"[^\"]*\"\\)*[^\"]*\"[^\"]*\\'"))
411 (insert "`")
412 (setq calc-alg-exp (minibuffer-contents))
413 (exit-minibuffer)))
415 (defvar calc-buffer)
417 (defun calcAlg-enter ()
418 (interactive)
419 (let* ((str (minibuffer-contents))
420 (exp (and (> (length str) 0)
421 (with-current-buffer calc-buffer
422 (math-read-exprs str)))))
423 (if (eq (car-safe exp) 'error)
424 (progn
425 (goto-char (minibuffer-prompt-end))
426 (forward-char (nth 1 exp))
427 (beep)
428 (calc-temp-minibuffer-message
429 (concat " [" (or (nth 2 exp) "Error") "]"))
430 (calc-clear-unread-commands))
431 (setq calc-alg-exp (if (calc-minibuffer-contains "\\` *\\[ *\\'")
432 '((incomplete vec))
433 exp))
434 (exit-minibuffer))))
436 (defun calcAlg-blink-matching-check (leftpt rightpt)
437 (let ((rightchar (char-before rightpt))
438 (leftchar (if leftpt (char-after leftpt))))
439 (if (and leftpt
440 (or (and (= rightchar ?\))
441 (= leftchar ?\[))
442 (and (= rightchar ?\])
443 (= leftchar ?\()))
444 (save-excursion
445 (goto-char leftpt)
446 (looking-at ".+\\(\\.\\.\\|\\\\dots\\|\\\\ldots\\)")))
447 ;; [2..5) perfectly valid!
449 (blink-matching-check-mismatch leftpt rightpt))))
451 ;;;###autoload
452 (defun calc-alg-digit-entry ()
453 (calc-alg-entry
454 (calc-digit-start-entry)))
456 ;; The variable calc-digit-value is initially declared in calc.el,
457 ;; but can be set by calcDigit-algebraic and calcDigit-edit.
458 (defvar calc-digit-value)
460 ;;;###autoload
461 (defun calcDigit-algebraic ()
462 (interactive)
463 (if (calc-minibuffer-contains ".*[@oh] *[^'m ]+[^'m]*\\'")
464 (calcDigit-key)
465 (setq calc-digit-value (minibuffer-contents))
466 (exit-minibuffer)))
468 ;;;###autoload
469 (defun calcDigit-edit ()
470 (interactive)
471 (calc-unread-command)
472 (setq calc-digit-value (minibuffer-contents))
473 (exit-minibuffer))
476 ;;; Algebraic expression parsing. [Public]
478 (defvar math-read-replacement-list
479 '(;; Misc symbols
480 ("±" "+/-") ; plus or minus
481 ("×" "*") ; multiplication sign
482 ("÷" ":") ; division sign
483 ("−" "-") ; subtraction sign
484 ("∕" "/") ; division sign
485 ("∗" "*") ; asterisk multiplication
486 ("∞" "inf") ; infinity symbol
487 ("≤" "<=")
488 ("≥" ">=")
489 ("≦" "<=")
490 ("≧" ">=")
491 ("µ" "μ")
492 ;; fractions
493 ("¼" "(1:4)") ; 1/4
494 ("½" "(1:2)") ; 1/2
495 ("¾" "(3:4)") ; 3/4
496 ("⅓" "(1:3)") ; 1/3
497 ("⅔" "(2:3)") ; 2/3
498 ("⅕" "(1:5)") ; 1/5
499 ("⅖" "(2:5)") ; 2/5
500 ("⅗" "(3:5)") ; 3/5
501 ("⅘" "(4:5)") ; 4/5
502 ("⅙" "(1:6)") ; 1/6
503 ("⅚" "(5:6)") ; 5/6
504 ("⅛" "(1:8)") ; 1/8
505 ("⅜" "(3:8)") ; 3/8
506 ("⅝" "(5:8)") ; 5/8
507 ("⅞" "(7:8)") ; 7/8
508 ("⅟" "1:") ; 1/...
509 ;; superscripts
510 ("⁰" "0") ; 0
511 ("¹" "1") ; 1
512 ("²" "2") ; 2
513 ("³" "3") ; 3
514 ("⁴" "4") ; 4
515 ("⁵" "5") ; 5
516 ("⁶" "6") ; 6
517 ("⁷" "7") ; 7
518 ("⁸" "8") ; 8
519 ("⁹" "9") ; 9
520 ("⁺" "+") ; +
521 ("⁻" "-") ; -
522 ("⁽" "(") ; (
523 ("⁾" ")") ; )
524 ("ⁿ" "n") ; n
525 ("ⁱ" "i") ; i
526 ;; subscripts
527 ("₀" "0") ; 0
528 ("₁" "1") ; 1
529 ("₂" "2") ; 2
530 ("₃" "3") ; 3
531 ("₄" "4") ; 4
532 ("₅" "5") ; 5
533 ("₆" "6") ; 6
534 ("₇" "7") ; 7
535 ("₈" "8") ; 8
536 ("₉" "9") ; 9
537 ("₊" "+") ; +
538 ("₋" "-") ; -
539 ("₍" "(") ; (
540 ("₎" ")")) ; )
541 "A list whose elements (old new) indicate replacements to make
542 in Calc algebraic input.")
544 (defvar math-read-superscripts
545 "⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁽⁾ⁿⁱ" ; 0123456789+-()ni
546 "A string consisting of the superscripts allowed by Calc.")
548 (defvar math-read-subscripts
549 "₀₁₂₃₄₅₆₇₈₉₊₋₍₎" ; 0123456789+-()
550 "A string consisting of the subscripts allowed by Calc.")
552 ;;;###autoload
553 (defun math-read-preprocess-string (str)
554 "Replace some substrings of STR by Calc equivalents."
555 (setq str
556 (replace-regexp-in-string (concat "[" math-read-superscripts "]+")
557 "^(\\&)" str))
558 (setq str
559 (replace-regexp-in-string (concat "[" math-read-subscripts "]+")
560 "_(\\&)" str))
561 (let ((rep-list math-read-replacement-list))
562 (while rep-list
563 (setq str
564 (replace-regexp-in-string (nth 0 (car rep-list))
565 (nth 1 (car rep-list)) str))
566 (setq rep-list (cdr rep-list))))
567 str)
569 ;; The next few variables are local to math-read-exprs (and math-read-expr
570 ;; in calc-ext.el), but are set in functions they call.
572 (defvar math-exp-pos)
573 (defvar math-exp-str)
574 (defvar math-exp-old-pos)
575 (defvar math-exp-token)
576 (defvar math-exp-keep-spaces)
577 (defvar math-expr-data)
579 ;;;###autoload
580 (defun math-read-exprs (math-exp-str)
581 (let ((math-exp-pos 0)
582 (math-exp-old-pos 0)
583 (math-exp-keep-spaces nil)
584 math-exp-token math-expr-data)
585 (setq math-exp-str (math-read-preprocess-string math-exp-str))
586 (if (memq calc-language calc-lang-allow-percentsigns)
587 (setq math-exp-str (math-remove-percentsigns math-exp-str)))
588 (if calc-language-input-filter
589 (setq math-exp-str (funcall calc-language-input-filter math-exp-str)))
590 (while (setq math-exp-token
591 (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str))
592 (setq math-exp-str
593 (concat (substring math-exp-str 0 math-exp-token) "\\dots"
594 (substring math-exp-str (+ math-exp-token 2)))))
595 (math-build-parse-table)
596 (math-read-token)
597 (let ((val (catch 'syntax (math-read-expr-list))))
598 (if (stringp val)
599 (list 'error math-exp-old-pos val)
600 (if (equal math-exp-token 'end)
602 (list 'error math-exp-old-pos "Syntax error"))))))
604 ;;;###autoload
605 (defun math-read-expr-list ()
606 (let* ((math-exp-keep-spaces nil)
607 (val (list (math-read-expr-level 0)))
608 (last val))
609 (while (equal math-expr-data ",")
610 (math-read-token)
611 (let ((rest (list (math-read-expr-level 0))))
612 (setcdr last rest)
613 (setq last rest)))
614 val))
616 (defvar calc-user-parse-table nil)
617 (defvar calc-last-main-parse-table nil)
618 (defvar calc-last-user-lang-parse-table nil)
619 (defvar calc-last-lang-parse-table nil)
620 (defvar calc-user-tokens nil)
621 (defvar calc-user-token-chars nil)
623 (defvar math-toks nil
624 "Tokens to pass between math-build-parse-table and math-find-user-tokens.")
626 ;;;###autoload
627 (defun math-build-parse-table ()
628 (let ((mtab (cdr (assq nil calc-user-parse-tables)))
629 (ltab (cdr (assq calc-language calc-user-parse-tables)))
630 (lltab (get calc-language 'math-parse-table)))
631 (or (and (eq mtab calc-last-main-parse-table)
632 (eq ltab calc-last-user-lang-parse-table)
633 (eq lltab calc-last-lang-parse-table))
634 (let ((p (append mtab ltab lltab))
635 (math-toks nil))
636 (setq calc-user-parse-table p)
637 (setq calc-user-token-chars nil)
638 (while p
639 (math-find-user-tokens (car (car p)))
640 (setq p (cdr p)))
641 (setq calc-user-tokens (mapconcat 'identity
642 (sort (mapcar 'car math-toks)
643 (function (lambda (x y)
644 (> (length x)
645 (length y)))))
646 "\\|")
647 calc-last-main-parse-table mtab
648 calc-last-user-lang-parse-table ltab
649 calc-last-lang-parse-table lltab)))))
651 ;;;###autoload
652 (defun math-find-user-tokens (p)
653 (while p
654 (cond ((and (stringp (car p))
655 (or (> (length (car p)) 1) (equal (car p) "$")
656 (equal (car p) "\""))
657 (string-match "[^a-zA-Zα-ωΑ-Ω0-9]" (car p)))
658 (let ((s (regexp-quote (car p))))
659 (if (string-match "\\`[a-zA-Zα-ωΑ-Ω0-9]" s)
660 (setq s (concat "\\<" s)))
661 (if (string-match "[a-zA-Zα-ωΑ-Ω0-9]\\'" s)
662 (setq s (concat s "\\>")))
663 (or (assoc s math-toks)
664 (progn
665 (setq math-toks (cons (list s) math-toks))
666 (or (memq (aref (car p) 0) calc-user-token-chars)
667 (setq calc-user-token-chars
668 (cons (aref (car p) 0)
669 calc-user-token-chars)))))))
670 ((consp (car p))
671 (math-find-user-tokens (nth 1 (car p)))
672 (or (eq (car (car p)) '\?)
673 (math-find-user-tokens (nth 2 (car p))))))
674 (setq p (cdr p))))
676 ;;;###autoload
677 (defun math-read-token ()
678 (if (>= math-exp-pos (length math-exp-str))
679 (setq math-exp-old-pos math-exp-pos
680 math-exp-token 'end
681 math-expr-data "\000")
682 (let (adfn
683 (ch (aref math-exp-str math-exp-pos)))
684 (setq math-exp-old-pos math-exp-pos)
685 (cond ((memq ch '(32 10 9))
686 (setq math-exp-pos (1+ math-exp-pos))
687 (if math-exp-keep-spaces
688 (setq math-exp-token 'space
689 math-expr-data " ")
690 (math-read-token)))
691 ((and (memq ch calc-user-token-chars)
692 (let ((case-fold-search nil))
693 (eq (string-match
694 calc-user-tokens math-exp-str math-exp-pos)
695 math-exp-pos)))
696 (setq math-exp-token 'punc
697 math-expr-data (math-match-substring math-exp-str 0)
698 math-exp-pos (match-end 0)))
699 ((or (and (>= ch ?a) (<= ch ?z))
700 (and (>= ch ?A) (<= ch ?Z))
701 (and (>= ch ?α) (<= ch ?ω))
702 (and (>= ch ?Α) (<= ch ?Ω)))
703 (string-match
704 (cond
705 ((and (memq calc-language calc-lang-allow-underscores)
706 (memq calc-language calc-lang-allow-percentsigns))
707 "[a-zA-Zα-ωΑ-Ω0-9_'#]*")
708 ((memq calc-language calc-lang-allow-underscores)
709 "[a-zA-Zα-ωΑ-Ω0-9_#]*")
710 (t "[a-zA-Zα-ωΑ-Ω0-9'#]*"))
711 math-exp-str math-exp-pos)
712 (setq math-exp-token 'symbol
713 math-exp-pos (match-end 0)
714 math-expr-data (math-restore-dashes
715 (math-match-substring math-exp-str 0)))
716 (if (setq adfn (get calc-language 'math-lang-adjust-words))
717 (funcall adfn)))
718 ((or (and (>= ch ?0) (<= ch ?9))
719 (and (eq ch '?\.)
720 (eq (string-match "\\.[0-9]" math-exp-str math-exp-pos)
721 math-exp-pos))
722 (and (eq ch '?_)
723 (eq (string-match "_\\.?[0-9]" math-exp-str math-exp-pos)
724 math-exp-pos)
725 (or (eq math-exp-pos 0)
726 (and (not (memq calc-language
727 calc-lang-allow-underscores))
728 (eq (string-match "[^])}\"a-zA-Zα-ωΑ-Ω0-9'$]_"
729 math-exp-str (1- math-exp-pos))
730 (1- math-exp-pos))))))
731 (or (and (memq calc-language calc-lang-c-type-hex)
732 (string-match "0[xX][0-9a-fA-F]+" math-exp-str math-exp-pos))
733 (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\(0*\\([2-9]\\|1[0-4]\\)\\(#[#]?\\|\\^\\^\\)[0-9a-dA-D.]+[eE][-+_]?[0-9]+\\|0*\\([2-9]\\|[0-2][0-9]\\|3[0-6]\\)\\(#[#]?\\|\\^\\^\\)[0-9a-zA-Zα-ωΑ-Ω:.]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?"
734 math-exp-str math-exp-pos))
735 (setq math-exp-token 'number
736 math-expr-data (math-match-substring math-exp-str 0)
737 math-exp-pos (match-end 0)))
738 ((and (setq adfn
739 (assq ch (get calc-language 'math-lang-read-symbol)))
740 (eval (nth 1 adfn)))
741 (eval (nth 2 adfn)))
742 ((eq ch ?\$)
743 (if (eq (string-match "\\$\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
744 math-exp-pos)
745 (setq math-expr-data (- (string-to-number (math-match-substring
746 math-exp-str 1))))
747 (string-match "\\$+" math-exp-str math-exp-pos)
748 (setq math-expr-data (- (match-end 0) (match-beginning 0))))
749 (setq math-exp-token 'dollar
750 math-exp-pos (match-end 0)))
751 ((eq ch ?\#)
752 (if (eq (string-match "#\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
753 math-exp-pos)
754 (setq math-expr-data (string-to-number
755 (math-match-substring math-exp-str 1))
756 math-exp-pos (match-end 0))
757 (setq math-expr-data 1
758 math-exp-pos (1+ math-exp-pos)))
759 (setq math-exp-token 'hash))
760 ((eq (string-match "~=\\|<=\\|>=\\|<>\\|/=\\|\\+/-\\|\\\\dots\\|\\\\ldots\\|\\*\\*\\|<<\\|>>\\|==\\|!=\\|&&&\\||||\\|!!!\\|&&\\|||\\|!!\\|:=\\|::\\|=>"
761 math-exp-str math-exp-pos)
762 math-exp-pos)
763 (setq math-exp-token 'punc
764 math-expr-data (math-match-substring math-exp-str 0)
765 math-exp-pos (match-end 0)))
766 ((and (eq ch ?\")
767 (string-match "\\(\"\\([^\"\\]\\|\\\\.\\)*\\)\\(\"\\|\\'\\)"
768 math-exp-str math-exp-pos))
769 (setq math-exp-token 'string
770 math-expr-data (math-match-substring math-exp-str 1)
771 math-exp-pos (match-end 0)))
772 ((and (setq adfn (get calc-language 'math-lang-read))
773 (eval (nth 0 adfn))
774 (eval (nth 1 adfn))))
775 ((eq (string-match "%%.*$" math-exp-str math-exp-pos) math-exp-pos)
776 (setq math-exp-pos (match-end 0))
777 (math-read-token))
779 (if (setq adfn (assq ch (get calc-language 'math-punc-table)))
780 (setq ch (cdr adfn)))
781 (setq math-exp-token 'punc
782 math-expr-data (char-to-string ch)
783 math-exp-pos (1+ math-exp-pos)))))))
785 (defconst math-alg-inequalities
786 '(calcFunc-lt calcFunc-gt calcFunc-leq calcFunc-geq
787 calcFunc-eq calcFunc-neq))
789 (defun math-read-expr-level (exp-prec &optional exp-term)
790 (let* ((math-expr-opers (math-expr-ops))
791 (x (math-read-factor))
792 (first t)
793 op op2)
794 (while (and (or (and calc-user-parse-table
795 (setq op (calc-check-user-syntax x exp-prec))
796 (setq x op
797 op '("2x" ident 999999 -1)))
798 (and (setq op (assoc math-expr-data math-expr-opers))
799 (/= (nth 2 op) -1)
800 (or (and (setq op2 (assoc
801 math-expr-data
802 (cdr (memq op math-expr-opers))))
803 (eq (= (nth 3 op) -1)
804 (/= (nth 3 op2) -1))
805 (eq (= (nth 3 op2) -1)
806 (not (math-factor-after)))
807 (setq op op2))
809 (and (or (eq (nth 2 op) -1)
810 (memq math-exp-token '(symbol number dollar hash))
811 (equal math-expr-data "(")
812 (and (equal math-expr-data "[")
813 (not (equal
814 (get calc-language
815 'math-function-open) "["))
816 (not (and math-exp-keep-spaces
817 (eq (car-safe x) 'vec)))))
818 (or (not (setq op (assoc math-expr-data math-expr-opers)))
819 (/= (nth 2 op) -1))
820 (or (not calc-user-parse-table)
821 (not (eq math-exp-token 'symbol))
822 (let ((p calc-user-parse-table))
823 (while (and p
824 (or (not (integerp
825 (car (car (car p)))))
826 (not (equal
827 (nth 1 (car (car p)))
828 math-expr-data))))
829 (setq p (cdr p)))
830 (not p)))
831 (setq op (assoc "2x" math-expr-opers))))
832 (not (and exp-term (equal math-expr-data exp-term)))
833 (>= (nth 2 op) exp-prec))
834 (if (not (equal (car op) "2x"))
835 (math-read-token))
836 (and (memq (nth 1 op) '(sdev mod))
837 (require 'calc-ext))
838 (setq x (cond ((consp (nth 1 op))
839 (funcall (car (nth 1 op)) x op))
840 ((eq (nth 3 op) -1)
841 (if (eq (nth 1 op) 'ident)
843 (if (eq (nth 1 op) 'closing)
844 (if (eq (nth 2 op) exp-prec)
845 (progn
846 (setq exp-prec 1000)
848 (throw 'syntax "Mismatched delimiters"))
849 (list (nth 1 op) x))))
850 ((and (not first)
851 (memq (nth 1 op) math-alg-inequalities)
852 (memq (car-safe x) math-alg-inequalities))
853 (require 'calc-ext)
854 (math-composite-inequalities x op))
855 (t (list (nth 1 op)
857 (math-read-expr-level (nth 3 op) exp-term))))
858 first nil))
861 ;; calc-arg-values is defined in calc-ext.el, but is used here.
862 (defvar calc-arg-values)
864 ;;;###autoload
865 (defun calc-check-user-syntax (&optional x prec)
866 (let ((p calc-user-parse-table)
867 (matches nil)
868 match rule)
869 (while (and p
870 (or (not (progn
871 (setq rule (car (car p)))
872 (if x
873 (and (integerp (car rule))
874 (>= (car rule) prec)
875 (equal math-expr-data
876 (car (setq rule (cdr rule)))))
877 (equal math-expr-data (car rule)))))
878 (let ((save-exp-pos math-exp-pos)
879 (save-exp-old-pos math-exp-old-pos)
880 (save-exp-token math-exp-token)
881 (save-exp-data math-expr-data))
882 (or (not (listp
883 (setq matches (calc-match-user-syntax rule))))
884 (let ((args (progn
885 (require 'calc-ext)
886 calc-arg-values))
887 (conds nil)
888 temp)
889 (if x
890 (setq matches (cons x matches)))
891 (setq match (cdr (car p)))
892 (while (and (eq (car-safe match)
893 'calcFunc-condition)
894 (= (length match) 3))
895 (setq conds (append (math-flatten-lands
896 (nth 2 match))
897 conds)
898 match (nth 1 match)))
899 (while (and conds match)
900 (require 'calc-ext)
901 (cond ((eq (car-safe (car conds))
902 'calcFunc-let)
903 (setq temp (car conds))
904 (or (= (length temp) 3)
905 (and (= (length temp) 2)
906 (eq (car-safe (nth 1 temp))
907 'calcFunc-assign)
908 (= (length (nth 1 temp)) 3)
909 (setq temp (nth 1 temp)))
910 (setq match nil))
911 (setq matches (cons
912 (math-normalize
913 (math-multi-subst
914 (nth 2 temp)
915 args matches))
916 matches)
917 args (cons (nth 1 temp)
918 args)))
919 ((and (eq (car-safe (car conds))
920 'calcFunc-matches)
921 (= (length (car conds)) 3))
922 (setq temp (calcFunc-vmatches
923 (math-multi-subst
924 (nth 1 (car conds))
925 args matches)
926 (nth 2 (car conds))))
927 (if (eq temp 0)
928 (setq match nil)
929 (while (setq temp (cdr temp))
930 (setq matches (cons (nth 2 (car temp))
931 matches)
932 args (cons (nth 1 (car temp))
933 args)))))
935 (or (math-is-true (math-simplify
936 (math-multi-subst
937 (car conds)
938 args matches)))
939 (setq match nil))))
940 (setq conds (cdr conds)))
941 (if match
942 (not (setq match (math-multi-subst
943 match args matches)))
944 (setq math-exp-old-pos save-exp-old-pos
945 math-exp-token save-exp-token
946 math-expr-data save-exp-data
947 math-exp-pos save-exp-pos)))))))
948 (setq p (cdr p)))
949 (and p match)))
951 ;;;###autoload
952 (defun calc-match-user-syntax (p &optional term)
953 (let ((matches nil)
954 (save-exp-pos math-exp-pos)
955 (save-exp-old-pos math-exp-old-pos)
956 (save-exp-token math-exp-token)
957 (save-exp-data math-expr-data)
959 (while (and p
960 (cond ((stringp (car p))
961 (and (equal math-expr-data (car p))
962 (progn
963 (math-read-token)
964 t)))
965 ((integerp (car p))
966 (and (setq m (catch 'syntax
967 (math-read-expr-level
968 (car p)
969 (if (cdr p)
970 (if (consp (nth 1 p))
971 (car (nth 1 (nth 1 p)))
972 (nth 1 p))
973 term))))
974 (not (stringp m))
975 (setq matches (nconc matches (list m)))))
976 ((eq (car (car p)) '\?)
977 (setq m (calc-match-user-syntax (nth 1 (car p))))
978 (or (nth 2 (car p))
979 (setq matches
980 (nconc matches
981 (list
982 (cons 'vec (and (listp m) m))))))
983 (or (listp m) (not (nth 2 (car p)))
984 (not (eq (aref (car (nth 2 (car p))) 0) ?\$))
985 (eq math-exp-token 'end)))
987 (setq m (calc-match-user-syntax (nth 1 (car p))
988 (car (nth 2 (car p)))))
989 (if (listp m)
990 (let ((vec (cons 'vec m))
991 opos mm)
992 (while (and (listp
993 (setq opos math-exp-pos
994 mm (calc-match-user-syntax
995 (or (nth 2 (car p))
996 (nth 1 (car p)))
997 (car (nth 2 (car p))))))
998 (> math-exp-pos opos))
999 (setq vec (nconc vec mm)))
1000 (setq matches (nconc matches (list vec))))
1001 (and (eq (car (car p)) '*)
1002 (setq matches (nconc matches (list '(vec)))))))))
1003 (setq p (cdr p)))
1004 (if p
1005 (setq math-exp-pos save-exp-pos
1006 math-exp-old-pos save-exp-old-pos
1007 math-exp-token save-exp-token
1008 math-expr-data save-exp-data
1009 matches "Failed"))
1010 matches))
1012 ;;;###autoload
1013 (defun math-remove-dashes (x)
1014 (if (string-match "\\`\\(.*\\)-\\(.*\\)\\'" x)
1015 (math-remove-dashes
1016 (concat (math-match-substring x 1) "#" (math-match-substring x 2)))
1019 (defun math-remove-percentsigns (x)
1020 (if (string-match "\\`\\(.*\\)%\\(.*\\)\\'" x)
1021 (math-remove-percentsigns
1022 (concat (math-match-substring x 1) "o'o" (math-match-substring x 2)))
1025 (defun math-restore-dashes (x)
1026 (if (string-match "\\`\\(.*\\)[#_]\\(.*\\)\\'" x)
1027 (math-restore-dashes
1028 (concat (math-match-substring x 1) "-" (math-match-substring x 2)))
1031 (defun math-restore-placeholders (x)
1032 "Replace placeholders by the proper characters in the symbol x.
1033 This includes `#' for `_' and `'' for `%'.
1034 If the current Calc language does not use placeholders, return nil."
1035 (if (or (memq calc-language calc-lang-allow-underscores)
1036 (memq calc-language calc-lang-allow-percentsigns))
1037 (let ((sx (symbol-name x)))
1038 (when (memq calc-language calc-lang-allow-percentsigns)
1039 (require 'calccomp)
1040 (setq sx (math-to-percentsigns sx)))
1041 (if (memq calc-language calc-lang-allow-underscores)
1042 (setq sx (math-string-restore-underscores sx)))
1043 (intern-soft sx))))
1045 (defun math-string-restore-underscores (x)
1046 "Replace pound signs by underscores in the string x."
1047 (if (string-match "\\`\\(.*\\)#\\(.*\\)\\'" x)
1048 (math-string-restore-underscores
1049 (concat (math-match-substring x 1) "_" (math-match-substring x 2)))
1052 ;;;###autoload
1053 (defun math-read-if (cond op)
1054 (let ((then (math-read-expr-level 0)))
1055 (or (equal math-expr-data ":")
1056 (throw 'syntax "Expected `:'"))
1057 (math-read-token)
1058 (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op)))))
1060 (defun math-factor-after ()
1061 (let ((math-exp-pos math-exp-pos)
1062 math-exp-old-pos math-exp-token math-expr-data)
1063 (math-read-token)
1064 (or (memq math-exp-token '(number symbol dollar hash string))
1065 (and (assoc math-expr-data '(("-") ("+") ("!") ("|") ("/")))
1066 (assoc (concat "u" math-expr-data) math-expr-opers))
1067 (eq (nth 2 (assoc math-expr-data math-expr-opers)) -1)
1068 (assoc math-expr-data '(("(") ("[") ("{"))))))
1070 (defun math-read-factor ()
1071 (let ((math-expr-opers (math-expr-ops))
1073 (cond ((eq math-exp-token 'number)
1074 (let ((num (math-read-number math-expr-data)))
1075 (if (not num)
1076 (progn
1077 (setq math-exp-old-pos math-exp-pos)
1078 (throw 'syntax "Bad format")))
1079 (math-read-token)
1080 (if (and math-read-expr-quotes
1081 (consp num))
1082 (list 'quote num)
1083 num)))
1084 ((and calc-user-parse-table
1085 (setq op (calc-check-user-syntax)))
1087 ((or (equal math-expr-data "-")
1088 (equal math-expr-data "+")
1089 (equal math-expr-data "!")
1090 (equal math-expr-data "|")
1091 (equal math-expr-data "/"))
1092 (setq math-expr-data (concat "u" math-expr-data))
1093 (math-read-factor))
1094 ((and (setq op (assoc math-expr-data math-expr-opers))
1095 (eq (nth 2 op) -1))
1096 (if (consp (nth 1 op))
1097 (funcall (car (nth 1 op)) op)
1098 (math-read-token)
1099 (let ((val (math-read-expr-level (nth 3 op))))
1100 (cond ((eq (nth 1 op) 'ident)
1101 val)
1102 ((and (Math-numberp val)
1103 (equal (car op) "u-"))
1104 (math-neg val))
1105 (t (list (nth 1 op) val))))))
1106 ((eq math-exp-token 'symbol)
1107 (let ((sym (intern math-expr-data)))
1108 (math-read-token)
1109 (if (equal math-expr-data calc-function-open)
1110 (let ((f (assq sym math-expr-function-mapping)))
1111 (math-read-token)
1112 (if (consp (cdr f))
1113 (funcall (car (cdr f)) f sym)
1114 (let ((args (if (or (equal math-expr-data calc-function-close)
1115 (eq math-exp-token 'end))
1117 (math-read-expr-list))))
1118 (if (not (or (equal math-expr-data calc-function-close)
1119 (eq math-exp-token 'end)))
1120 (throw 'syntax "Expected `)'"))
1121 (math-read-token)
1122 (if (and (memq calc-language
1123 calc-lang-parens-are-subscripts)
1124 args
1125 (require 'calc-ext)
1126 (let ((calc-matrix-mode 'scalar))
1127 (math-known-matrixp
1128 (list 'var sym
1129 (intern
1130 (concat "var-"
1131 (symbol-name sym)))))))
1132 (math-parse-fortran-subscr sym args)
1133 (if f
1134 (setq sym (cdr f))
1135 (and (= (aref (symbol-name sym) 0) ?\\)
1136 (< (prefix-numeric-value calc-language-option)
1138 (setq sym (intern (substring (symbol-name sym)
1139 1))))
1140 (or (string-match "-" (symbol-name sym))
1141 (setq sym (intern
1142 (concat "calcFunc-"
1143 (symbol-name sym))))))
1144 (cons sym args)))))
1145 (if math-read-expr-quotes
1147 (let ((val (list 'var
1148 (intern (math-remove-dashes
1149 (symbol-name sym)))
1150 (if (string-match "-" (symbol-name sym))
1152 (intern (concat "var-"
1153 (symbol-name sym)))))))
1154 (let ((v (or
1155 (assq (nth 1 val) math-expr-variable-mapping)
1156 (assq (math-restore-placeholders (nth 1 val))
1157 math-expr-variable-mapping))))
1158 (and v (setq val (if (consp (cdr v))
1159 (funcall (car (cdr v)) v val)
1160 (list 'var
1161 (intern
1162 (substring (symbol-name (cdr v))
1164 (cdr v))))))
1165 (while (and (memq calc-language
1166 calc-lang-brackets-are-subscripts)
1167 (equal math-expr-data "["))
1168 (math-read-token)
1169 (let ((el (math-read-expr-list)))
1170 (while el
1171 (setq val (append (list 'calcFunc-subscr val)
1172 (list (car el))))
1173 (setq el (cdr el))))
1174 (if (equal math-expr-data "]")
1175 (math-read-token)
1176 (throw 'syntax "Expected `]'")))
1177 val)))))
1178 ((eq math-exp-token 'dollar)
1179 (let ((abs (if (> math-expr-data 0) math-expr-data (- math-expr-data))))
1180 (if (>= (length calc-dollar-values) abs)
1181 (let ((num math-expr-data))
1182 (math-read-token)
1183 (setq calc-dollar-used (max calc-dollar-used num))
1184 (math-check-complete (nth (1- abs) calc-dollar-values)))
1185 (throw 'syntax (if calc-dollar-values
1186 "Too many $'s"
1187 "$'s not allowed in this context")))))
1188 ((eq math-exp-token 'hash)
1189 (or calc-hashes-used
1190 (throw 'syntax "#'s not allowed in this context"))
1191 (require 'calc-ext)
1192 (if (<= math-expr-data (length calc-arg-values))
1193 (let ((num math-expr-data))
1194 (math-read-token)
1195 (setq calc-hashes-used (max calc-hashes-used num))
1196 (nth (1- num) calc-arg-values))
1197 (throw 'syntax "Too many # arguments")))
1198 ((equal math-expr-data "(")
1199 (let* ((exp (let ((math-exp-keep-spaces nil))
1200 (math-read-token)
1201 (if (or (equal math-expr-data "\\dots")
1202 (equal math-expr-data "\\ldots"))
1203 '(neg (var inf var-inf))
1204 (math-read-expr-level 0)))))
1205 (let ((math-exp-keep-spaces nil))
1206 (cond
1207 ((equal math-expr-data ",")
1208 (progn
1209 (math-read-token)
1210 (let ((exp2 (math-read-expr-level 0)))
1211 (setq exp
1212 (if (and exp2 (Math-realp exp) (Math-realp exp2))
1213 (math-normalize (list 'cplx exp exp2))
1214 (list '+ exp (list '* exp2 '(var i var-i))))))))
1215 ((equal math-expr-data ";")
1216 (progn
1217 (math-read-token)
1218 (let ((exp2 (math-read-expr-level 0)))
1219 (setq exp (if (and exp2 (Math-realp exp)
1220 (Math-anglep exp2))
1221 (math-normalize (list 'polar exp exp2))
1222 (require 'calc-ext)
1223 (list '* exp
1224 (list 'calcFunc-exp
1225 (list '*
1226 (math-to-radians-2 exp2)
1227 '(var i var-i)))))))))
1228 ((or (equal math-expr-data "\\dots")
1229 (equal math-expr-data "\\ldots"))
1230 (progn
1231 (math-read-token)
1232 (let ((exp2 (if (or (equal math-expr-data ")")
1233 (equal math-expr-data "]")
1234 (eq math-exp-token 'end))
1235 '(var inf var-inf)
1236 (math-read-expr-level 0))))
1237 (setq exp
1238 (list 'intv
1239 (if (equal math-expr-data ")") 0 1)
1241 exp2)))))))
1242 (if (not (or (equal math-expr-data ")")
1243 (and (equal math-expr-data "]") (eq (car-safe exp) 'intv))
1244 (eq math-exp-token 'end)))
1245 (throw 'syntax "Expected `)'"))
1246 (math-read-token)
1247 exp))
1248 ((eq math-exp-token 'string)
1249 (require 'calc-ext)
1250 (math-read-string))
1251 ((equal math-expr-data "[")
1252 (require 'calc-ext)
1253 (math-read-brackets t "]"))
1254 ((equal math-expr-data "{")
1255 (require 'calc-ext)
1256 (math-read-brackets nil "}"))
1257 ((equal math-expr-data "<")
1258 (require 'calc-ext)
1259 (math-read-angle-brackets))
1260 (t (throw 'syntax "Expected a number")))))
1262 (provide 'calc-aent)
1264 ;; Local variables:
1265 ;; generated-autoload-file: "calc-loaddefs.el"
1266 ;; End:
1268 ;;; calc-aent.el ends here