Nuke arch-tags.
[emacs.git] / lisp / calc / calc-aent.el
blob7ab908bd50642ba0d957eab8af99910e9338d3cc
1 ;;; calc-aent.el --- algebraic entry functions for Calc
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
6 ;; Author: Dave Gillespie <daveg@synaptics.com>
7 ;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;;; Code:
28 ;; This file is autoloaded from calc.el.
30 (require 'calc)
31 (require 'calc-macs)
33 ;; Declare functions which are defined elsewhere.
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))
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 ()
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 (eq last-command-event 10)
113 (insert shortbuf)
114 (kill-new shortbuf)))))
116 ;;;###autoload
117 (defun calc-do-calc-eval (str separator args)
118 (calc-check-defines)
119 (catch 'calc-error
120 (save-excursion
121 (calc-create-buffer)
122 (cond
123 ((and (consp str) (not (symbolp (car str))))
124 (let ((calc-language nil)
125 (math-expr-opers (math-standard-ops))
126 (calc-internal-prec 12)
127 (calc-word-size 32)
128 (calc-symbolic-mode nil)
129 (calc-matrix-mode nil)
130 (calc-angle-mode 'deg)
131 (calc-number-radix 10)
132 (calc-twos-complement-mode nil)
133 (calc-leading-zeros nil)
134 (calc-group-digits nil)
135 (calc-point-char ".")
136 (calc-frac-format '(":" nil))
137 (calc-prefer-frac nil)
138 (calc-hms-format "%s@ %s' %s\"")
139 (calc-date-format '((H ":" mm C SS pp " ")
140 Www " " Mmm " " D ", " YYYY))
141 (calc-float-format '(float 0))
142 (calc-full-float-format '(float 0))
143 (calc-complex-format nil)
144 (calc-matrix-just nil)
145 (calc-full-vectors t)
146 (calc-break-vectors nil)
147 (calc-vector-commas ",")
148 (calc-vector-brackets "[]")
149 (calc-matrix-brackets '(R O))
150 (calc-complex-mode 'cplx)
151 (calc-infinite-mode nil)
152 (calc-display-strings nil)
153 (calc-simplify-mode nil)
154 (calc-display-working-message 'lots)
155 (strp (cdr str)))
156 (while strp
157 (set (car strp) (nth 1 strp))
158 (setq strp (cdr (cdr strp))))
159 (calc-do-calc-eval (car str) separator args)))
160 ((eq separator 'eval)
161 (eval str))
162 ((eq separator 'macro)
163 (require 'calc-ext)
164 (let* ((calc-buffer (current-buffer))
165 (calc-window (get-buffer-window calc-buffer))
166 (save-window (selected-window)))
167 (if calc-window
168 (unwind-protect
169 (progn
170 (select-window calc-window)
171 (calc-execute-kbd-macro str nil (car args)))
172 (and (window-point save-window)
173 (select-window save-window)))
174 (save-window-excursion
175 (select-window (get-largest-window))
176 (switch-to-buffer calc-buffer)
177 (calc-execute-kbd-macro str nil (car args)))))
178 nil)
179 ((eq separator 'pop)
180 (or (not (integerp str))
181 (= str 0)
182 (calc-pop (min str (calc-stack-size))))
183 (calc-stack-size))
184 ((eq separator 'top)
185 (and (integerp str)
186 (> str 0)
187 (<= str (calc-stack-size))
188 (math-format-value (calc-top-n str (car args)) 1000)))
189 ((eq separator 'rawtop)
190 (and (integerp str)
191 (> str 0)
192 (<= str (calc-stack-size))
193 (calc-top-n str (car args))))
195 (let* ((calc-command-flags nil)
196 (calc-next-why nil)
197 (calc-language (if (memq calc-language '(nil big))
198 'flat calc-language))
199 (calc-dollar-values (mapcar
200 (function
201 (lambda (x)
202 (if (stringp x)
203 (progn
204 (setq x (math-read-exprs x))
205 (if (eq (car-safe x)
206 'error)
207 (throw 'calc-error
208 (calc-eval-error
209 (cdr x)))
210 (car x)))
211 x)))
212 args))
213 (calc-dollar-used 0)
214 (res (if (stringp str)
215 (math-read-exprs str)
216 (list str)))
217 buf)
218 (if (eq (car res) 'error)
219 (calc-eval-error (cdr res))
220 (setq res (mapcar 'calc-normalize res))
221 (and (memq 'clear-message calc-command-flags)
222 (message ""))
223 (cond ((eq separator 'pred)
224 (require 'calc-ext)
225 (if (= (length res) 1)
226 (math-is-true (car res))
227 (calc-eval-error '(0 "Single value expected"))))
228 ((eq separator 'raw)
229 (if (= (length res) 1)
230 (car res)
231 (calc-eval-error '(0 "Single value expected"))))
232 ((eq separator 'list)
233 res)
234 ((memq separator '(num rawnum))
235 (if (= (length res) 1)
236 (if (math-constp (car res))
237 (if (eq separator 'num)
238 (math-format-value (car res) 1000)
239 (car res))
240 (calc-eval-error
241 (list 0
242 (if calc-next-why
243 (calc-explain-why (car calc-next-why))
244 "Number expected"))))
245 (calc-eval-error '(0 "Single value expected"))))
246 ((eq separator 'push)
247 (calc-push-list res)
248 nil)
249 (t (while res
250 (setq buf (concat buf
251 (and buf (or separator ", "))
252 (math-format-value (car res) 1000))
253 res (cdr res)))
254 buf)))))))))
256 (defvar calc-eval-error nil
257 "Determines how calc handles errors.
258 If nil, return a list containing the character position of error.
259 STRING means return error message as string rather than list.
260 The value t means abort and give an error message.")
262 (defun calc-eval-error (msg)
263 (if calc-eval-error
264 (if (eq calc-eval-error 'string)
265 (nth 1 msg)
266 (error "%s" (nth 1 msg)))
267 msg))
270 ;;;; Reading an expression in algebraic form.
272 ;;;###autoload
273 (defun calc-auto-algebraic-entry (&optional prefix)
274 (interactive "P")
275 (calc-algebraic-entry prefix t))
277 ;;;###autoload
278 (defun calc-algebraic-entry (&optional prefix auto)
279 (interactive "P")
280 (calc-wrapper
281 (let ((calc-language (if prefix nil calc-language))
282 (math-expr-opers (if prefix (math-standard-ops) (math-expr-ops))))
283 (calc-alg-entry (and auto (char-to-string last-command-event))))))
285 (defvar calc-alg-entry-history nil
286 "History for algebraic entry.")
288 ;;;###autoload
289 (defun calc-alg-entry (&optional initial prompt)
290 (let* ((sel-mode nil)
291 (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 (cond ((eq last-command-event ?e)
455 (if (> calc-number-radix 14) (format "%d.^" calc-number-radix) "1e"))
456 ((eq last-command-event ?#) (format "%d#" calc-number-radix))
457 ((eq last-command-event ?_) "-")
458 ((eq last-command-event ?@) "0@ ")
459 (t (char-to-string last-command-event)))))
461 ;; The variable calc-digit-value is initially declared in calc.el,
462 ;; but can be set by calcDigit-algebraic and calcDigit-edit.
463 (defvar calc-digit-value)
465 ;;;###autoload
466 (defun calcDigit-algebraic ()
467 (interactive)
468 (if (calc-minibuffer-contains ".*[@oh] *[^'m ]+[^'m]*\\'")
469 (calcDigit-key)
470 (setq calc-digit-value (minibuffer-contents))
471 (exit-minibuffer)))
473 ;;;###autoload
474 (defun calcDigit-edit ()
475 (interactive)
476 (calc-unread-command)
477 (setq calc-digit-value (minibuffer-contents))
478 (exit-minibuffer))
481 ;;; Algebraic expression parsing. [Public]
483 (defvar math-read-replacement-list
484 '(;; Misc symbols
485 ("±" "+/-") ; plus or minus
486 ("×" "*") ; multiplication sign
487 ("÷" ":") ; division sign
488 ("−" "-") ; subtraction sign
489 ("∕" "/") ; division sign
490 ("∗" "*") ; asterisk multiplication
491 ("∞" "inf") ; infinity symbol
492 ("≤" "<=")
493 ("≥" ">=")
494 ("≦" "<=")
495 ("≧" ">=")
496 ("µ" "μ")
497 ;; fractions
498 ("¼" "(1:4)") ; 1/4
499 ("½" "(1:2)") ; 1/2
500 ("¾" "(3:4)") ; 3/4
501 ("⅓" "(1:3)") ; 1/3
502 ("⅔" "(2:3)") ; 2/3
503 ("⅕" "(1:5)") ; 1/5
504 ("⅖" "(2:5)") ; 2/5
505 ("⅗" "(3:5)") ; 3/5
506 ("⅘" "(4:5)") ; 4/5
507 ("⅙" "(1:6)") ; 1/6
508 ("⅚" "(5:6)") ; 5/6
509 ("⅛" "(1:8)") ; 1/8
510 ("⅜" "(3:8)") ; 3/8
511 ("⅝" "(5:8)") ; 5/8
512 ("⅞" "(7:8)") ; 7/8
513 ("⅟" "1:") ; 1/...
514 ;; superscripts
515 ("⁰" "0") ; 0
516 ("¹" "1") ; 1
517 ("²" "2") ; 2
518 ("³" "3") ; 3
519 ("⁴" "4") ; 4
520 ("⁵" "5") ; 5
521 ("⁶" "6") ; 6
522 ("⁷" "7") ; 7
523 ("⁸" "8") ; 8
524 ("⁹" "9") ; 9
525 ("⁺" "+") ; +
526 ("⁻" "-") ; -
527 ("⁽" "(") ; (
528 ("⁾" ")") ; )
529 ("ⁿ" "n") ; n
530 ("ⁱ" "i") ; i
531 ;; subscripts
532 ("₀" "0") ; 0
533 ("₁" "1") ; 1
534 ("₂" "2") ; 2
535 ("₃" "3") ; 3
536 ("₄" "4") ; 4
537 ("₅" "5") ; 5
538 ("₆" "6") ; 6
539 ("₇" "7") ; 7
540 ("₈" "8") ; 8
541 ("₉" "9") ; 9
542 ("₊" "+") ; +
543 ("₋" "-") ; -
544 ("₍" "(") ; (
545 ("₎" ")")) ; )
546 "A list whose elements (old new) indicate replacements to make
547 in Calc algebraic input.")
549 (defvar math-read-superscripts
550 "⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁽⁾ⁿⁱ" ; 0123456789+-()ni
551 "A string consisting of the superscripts allowed by Calc.")
553 (defvar math-read-subscripts
554 "₀₁₂₃₄₅₆₇₈₉₊₋₍₎" ; 0123456789+-()
555 "A string consisting of the subscripts allowed by Calc.")
557 ;;;###autoload
558 (defun math-read-preprocess-string (str)
559 "Replace some substrings of STR by Calc equivalents."
560 (setq str
561 (replace-regexp-in-string (concat "[" math-read-superscripts "]+")
562 "^(\\&)" str))
563 (setq str
564 (replace-regexp-in-string (concat "[" math-read-subscripts "]+")
565 "_(\\&)" str))
566 (let ((rep-list math-read-replacement-list))
567 (while rep-list
568 (setq str
569 (replace-regexp-in-string (nth 0 (car rep-list))
570 (nth 1 (car rep-list)) str))
571 (setq rep-list (cdr rep-list))))
572 str)
574 ;; The next few variables are local to math-read-exprs (and math-read-expr
575 ;; in calc-ext.el), but are set in functions they call.
577 (defvar math-exp-pos)
578 (defvar math-exp-str)
579 (defvar math-exp-old-pos)
580 (defvar math-exp-token)
581 (defvar math-exp-keep-spaces)
582 (defvar math-expr-data)
584 ;;;###autoload
585 (defun math-read-exprs (math-exp-str)
586 (let ((math-exp-pos 0)
587 (math-exp-old-pos 0)
588 (math-exp-keep-spaces nil)
589 math-exp-token math-expr-data)
590 (setq math-exp-str (math-read-preprocess-string math-exp-str))
591 (if (memq calc-language calc-lang-allow-percentsigns)
592 (setq math-exp-str (math-remove-percentsigns math-exp-str)))
593 (if calc-language-input-filter
594 (setq math-exp-str (funcall calc-language-input-filter math-exp-str)))
595 (while (setq math-exp-token
596 (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str))
597 (setq math-exp-str
598 (concat (substring math-exp-str 0 math-exp-token) "\\dots"
599 (substring math-exp-str (+ math-exp-token 2)))))
600 (math-build-parse-table)
601 (math-read-token)
602 (let ((val (catch 'syntax (math-read-expr-list))))
603 (if (stringp val)
604 (list 'error math-exp-old-pos val)
605 (if (equal math-exp-token 'end)
607 (list 'error math-exp-old-pos "Syntax error"))))))
609 ;;;###autoload
610 (defun math-read-expr-list ()
611 (let* ((math-exp-keep-spaces nil)
612 (val (list (math-read-expr-level 0)))
613 (last val))
614 (while (equal math-expr-data ",")
615 (math-read-token)
616 (let ((rest (list (math-read-expr-level 0))))
617 (setcdr last rest)
618 (setq last rest)))
619 val))
621 (defvar calc-user-parse-table nil)
622 (defvar calc-last-main-parse-table nil)
623 (defvar calc-last-user-lang-parse-table nil)
624 (defvar calc-last-lang-parse-table nil)
625 (defvar calc-user-tokens nil)
626 (defvar calc-user-token-chars nil)
628 (defvar math-toks nil
629 "Tokens to pass between math-build-parse-table and math-find-user-tokens.")
631 ;;;###autoload
632 (defun math-build-parse-table ()
633 (let ((mtab (cdr (assq nil calc-user-parse-tables)))
634 (ltab (cdr (assq calc-language calc-user-parse-tables)))
635 (lltab (get calc-language 'math-parse-table)))
636 (or (and (eq mtab calc-last-main-parse-table)
637 (eq ltab calc-last-user-lang-parse-table)
638 (eq lltab calc-last-lang-parse-table))
639 (let ((p (append mtab ltab lltab))
640 (math-toks nil))
641 (setq calc-user-parse-table p)
642 (setq calc-user-token-chars nil)
643 (while p
644 (math-find-user-tokens (car (car p)))
645 (setq p (cdr p)))
646 (setq calc-user-tokens (mapconcat 'identity
647 (sort (mapcar 'car math-toks)
648 (function (lambda (x y)
649 (> (length x)
650 (length y)))))
651 "\\|")
652 calc-last-main-parse-table mtab
653 calc-last-user-lang-parse-table ltab
654 calc-last-lang-parse-table lltab)))))
656 ;;;###autoload
657 (defun math-find-user-tokens (p)
658 (while p
659 (cond ((and (stringp (car p))
660 (or (> (length (car p)) 1) (equal (car p) "$")
661 (equal (car p) "\""))
662 (string-match "[^a-zA-Zα-ωΑ-Ω0-9]" (car p)))
663 (let ((s (regexp-quote (car p))))
664 (if (string-match "\\`[a-zA-Zα-ωΑ-Ω0-9]" s)
665 (setq s (concat "\\<" s)))
666 (if (string-match "[a-zA-Zα-ωΑ-Ω0-9]\\'" s)
667 (setq s (concat s "\\>")))
668 (or (assoc s math-toks)
669 (progn
670 (setq math-toks (cons (list s) math-toks))
671 (or (memq (aref (car p) 0) calc-user-token-chars)
672 (setq calc-user-token-chars
673 (cons (aref (car p) 0)
674 calc-user-token-chars)))))))
675 ((consp (car p))
676 (math-find-user-tokens (nth 1 (car p)))
677 (or (eq (car (car p)) '\?)
678 (math-find-user-tokens (nth 2 (car p))))))
679 (setq p (cdr p))))
681 ;;;###autoload
682 (defun math-read-token ()
683 (if (>= math-exp-pos (length math-exp-str))
684 (setq math-exp-old-pos math-exp-pos
685 math-exp-token 'end
686 math-expr-data "\000")
687 (let (adfn
688 (ch (aref math-exp-str math-exp-pos)))
689 (setq math-exp-old-pos math-exp-pos)
690 (cond ((memq ch '(32 10 9))
691 (setq math-exp-pos (1+ math-exp-pos))
692 (if math-exp-keep-spaces
693 (setq math-exp-token 'space
694 math-expr-data " ")
695 (math-read-token)))
696 ((and (memq ch calc-user-token-chars)
697 (let ((case-fold-search nil))
698 (eq (string-match
699 calc-user-tokens math-exp-str math-exp-pos)
700 math-exp-pos)))
701 (setq math-exp-token 'punc
702 math-expr-data (math-match-substring math-exp-str 0)
703 math-exp-pos (match-end 0)))
704 ((or (and (>= ch ?a) (<= ch ?z))
705 (and (>= ch ?A) (<= ch ?Z))
706 (and (>= ch ?α) (<= ch ?ω))
707 (and (>= ch ?Α) (<= ch ?Ω)))
708 (string-match
709 (cond
710 ((and (memq calc-language calc-lang-allow-underscores)
711 (memq calc-language calc-lang-allow-percentsigns))
712 "[a-zA-Zα-ωΑ-Ω0-9_'#]*")
713 ((memq calc-language calc-lang-allow-underscores)
714 "[a-zA-Zα-ωΑ-Ω0-9_#]*")
715 (t "[a-zA-Zα-ωΑ-Ω0-9'#]*"))
716 math-exp-str math-exp-pos)
717 (setq math-exp-token 'symbol
718 math-exp-pos (match-end 0)
719 math-expr-data (math-restore-dashes
720 (math-match-substring math-exp-str 0)))
721 (if (setq adfn (get calc-language 'math-lang-adjust-words))
722 (funcall adfn)))
723 ((or (and (>= ch ?0) (<= ch ?9))
724 (and (eq ch '?\.)
725 (eq (string-match "\\.[0-9]" math-exp-str math-exp-pos)
726 math-exp-pos))
727 (and (eq ch '?_)
728 (eq (string-match "_\\.?[0-9]" math-exp-str math-exp-pos)
729 math-exp-pos)
730 (or (eq math-exp-pos 0)
731 (and (not (memq calc-language
732 calc-lang-allow-underscores))
733 (eq (string-match "[^])}\"a-zA-Zα-ωΑ-Ω0-9'$]_"
734 math-exp-str (1- math-exp-pos))
735 (1- math-exp-pos))))))
736 (or (and (memq calc-language calc-lang-c-type-hex)
737 (string-match "0[xX][0-9a-fA-F]+" math-exp-str math-exp-pos))
738 (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]+\\)?\"?\\)?"
739 math-exp-str math-exp-pos))
740 (setq math-exp-token 'number
741 math-expr-data (math-match-substring math-exp-str 0)
742 math-exp-pos (match-end 0)))
743 ((and (setq adfn
744 (assq ch (get calc-language 'math-lang-read-symbol)))
745 (eval (nth 1 adfn)))
746 (eval (nth 2 adfn)))
747 ((eq ch ?\$)
748 (if (eq (string-match "\\$\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
749 math-exp-pos)
750 (setq math-expr-data (- (string-to-number (math-match-substring
751 math-exp-str 1))))
752 (string-match "\\$+" math-exp-str math-exp-pos)
753 (setq math-expr-data (- (match-end 0) (match-beginning 0))))
754 (setq math-exp-token 'dollar
755 math-exp-pos (match-end 0)))
756 ((eq ch ?\#)
757 (if (eq (string-match "#\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
758 math-exp-pos)
759 (setq math-expr-data (string-to-number
760 (math-match-substring math-exp-str 1))
761 math-exp-pos (match-end 0))
762 (setq math-expr-data 1
763 math-exp-pos (1+ math-exp-pos)))
764 (setq math-exp-token 'hash))
765 ((eq (string-match "~=\\|<=\\|>=\\|<>\\|/=\\|\\+/-\\|\\\\dots\\|\\\\ldots\\|\\*\\*\\|<<\\|>>\\|==\\|!=\\|&&&\\||||\\|!!!\\|&&\\|||\\|!!\\|:=\\|::\\|=>"
766 math-exp-str math-exp-pos)
767 math-exp-pos)
768 (setq math-exp-token 'punc
769 math-expr-data (math-match-substring math-exp-str 0)
770 math-exp-pos (match-end 0)))
771 ((and (eq ch ?\")
772 (string-match "\\(\"\\([^\"\\]\\|\\\\.\\)*\\)\\(\"\\|\\'\\)"
773 math-exp-str math-exp-pos))
774 (setq math-exp-token 'string
775 math-expr-data (math-match-substring math-exp-str 1)
776 math-exp-pos (match-end 0)))
777 ((and (setq adfn (get calc-language 'math-lang-read))
778 (eval (nth 0 adfn))
779 (eval (nth 1 adfn))))
780 ((eq (string-match "%%.*$" math-exp-str math-exp-pos) math-exp-pos)
781 (setq math-exp-pos (match-end 0))
782 (math-read-token))
784 (if (setq adfn (assq ch (get calc-language 'math-punc-table)))
785 (setq ch (cdr adfn)))
786 (setq math-exp-token 'punc
787 math-expr-data (char-to-string ch)
788 math-exp-pos (1+ math-exp-pos)))))))
790 (defconst math-alg-inequalities
791 '(calcFunc-lt calcFunc-gt calcFunc-leq calcFunc-geq
792 calcFunc-eq calcFunc-neq))
794 (defun math-read-expr-level (exp-prec &optional exp-term)
795 (let* ((math-expr-opers (math-expr-ops))
796 (x (math-read-factor))
797 (first t)
798 op op2)
799 (while (and (or (and calc-user-parse-table
800 (setq op (calc-check-user-syntax x exp-prec))
801 (setq x op
802 op '("2x" ident 999999 -1)))
803 (and (setq op (assoc math-expr-data math-expr-opers))
804 (/= (nth 2 op) -1)
805 (or (and (setq op2 (assoc
806 math-expr-data
807 (cdr (memq op math-expr-opers))))
808 (eq (= (nth 3 op) -1)
809 (/= (nth 3 op2) -1))
810 (eq (= (nth 3 op2) -1)
811 (not (math-factor-after)))
812 (setq op op2))
814 (and (or (eq (nth 2 op) -1)
815 (memq math-exp-token '(symbol number dollar hash))
816 (equal math-expr-data "(")
817 (and (equal math-expr-data "[")
818 (not (equal
819 (get calc-language
820 'math-function-open) "["))
821 (not (and math-exp-keep-spaces
822 (eq (car-safe x) 'vec)))))
823 (or (not (setq op (assoc math-expr-data math-expr-opers)))
824 (/= (nth 2 op) -1))
825 (or (not calc-user-parse-table)
826 (not (eq math-exp-token 'symbol))
827 (let ((p calc-user-parse-table))
828 (while (and p
829 (or (not (integerp
830 (car (car (car p)))))
831 (not (equal
832 (nth 1 (car (car p)))
833 math-expr-data))))
834 (setq p (cdr p)))
835 (not p)))
836 (setq op (assoc "2x" math-expr-opers))))
837 (not (and exp-term (equal math-expr-data exp-term)))
838 (>= (nth 2 op) exp-prec))
839 (if (not (equal (car op) "2x"))
840 (math-read-token))
841 (and (memq (nth 1 op) '(sdev mod))
842 (require 'calc-ext))
843 (setq x (cond ((consp (nth 1 op))
844 (funcall (car (nth 1 op)) x op))
845 ((eq (nth 3 op) -1)
846 (if (eq (nth 1 op) 'ident)
848 (if (eq (nth 1 op) 'closing)
849 (if (eq (nth 2 op) exp-prec)
850 (progn
851 (setq exp-prec 1000)
853 (throw 'syntax "Mismatched delimiters"))
854 (list (nth 1 op) x))))
855 ((and (not first)
856 (memq (nth 1 op) math-alg-inequalities)
857 (memq (car-safe x) math-alg-inequalities))
858 (require 'calc-ext)
859 (math-composite-inequalities x op))
860 (t (list (nth 1 op)
862 (math-read-expr-level (nth 3 op) exp-term))))
863 first nil))
866 ;; calc-arg-values is defined in calc-ext.el, but is used here.
867 (defvar calc-arg-values)
869 ;;;###autoload
870 (defun calc-check-user-syntax (&optional x prec)
871 (let ((p calc-user-parse-table)
872 (matches nil)
873 match rule)
874 (while (and p
875 (or (not (progn
876 (setq rule (car (car p)))
877 (if x
878 (and (integerp (car rule))
879 (>= (car rule) prec)
880 (equal math-expr-data
881 (car (setq rule (cdr rule)))))
882 (equal math-expr-data (car rule)))))
883 (let ((save-exp-pos math-exp-pos)
884 (save-exp-old-pos math-exp-old-pos)
885 (save-exp-token math-exp-token)
886 (save-exp-data math-expr-data))
887 (or (not (listp
888 (setq matches (calc-match-user-syntax rule))))
889 (let ((args (progn
890 (require 'calc-ext)
891 calc-arg-values))
892 (conds nil)
893 temp)
894 (if x
895 (setq matches (cons x matches)))
896 (setq match (cdr (car p)))
897 (while (and (eq (car-safe match)
898 'calcFunc-condition)
899 (= (length match) 3))
900 (setq conds (append (math-flatten-lands
901 (nth 2 match))
902 conds)
903 match (nth 1 match)))
904 (while (and conds match)
905 (require 'calc-ext)
906 (cond ((eq (car-safe (car conds))
907 'calcFunc-let)
908 (setq temp (car conds))
909 (or (= (length temp) 3)
910 (and (= (length temp) 2)
911 (eq (car-safe (nth 1 temp))
912 'calcFunc-assign)
913 (= (length (nth 1 temp)) 3)
914 (setq temp (nth 1 temp)))
915 (setq match nil))
916 (setq matches (cons
917 (math-normalize
918 (math-multi-subst
919 (nth 2 temp)
920 args matches))
921 matches)
922 args (cons (nth 1 temp)
923 args)))
924 ((and (eq (car-safe (car conds))
925 'calcFunc-matches)
926 (= (length (car conds)) 3))
927 (setq temp (calcFunc-vmatches
928 (math-multi-subst
929 (nth 1 (car conds))
930 args matches)
931 (nth 2 (car conds))))
932 (if (eq temp 0)
933 (setq match nil)
934 (while (setq temp (cdr temp))
935 (setq matches (cons (nth 2 (car temp))
936 matches)
937 args (cons (nth 1 (car temp))
938 args)))))
940 (or (math-is-true (math-simplify
941 (math-multi-subst
942 (car conds)
943 args matches)))
944 (setq match nil))))
945 (setq conds (cdr conds)))
946 (if match
947 (not (setq match (math-multi-subst
948 match args matches)))
949 (setq math-exp-old-pos save-exp-old-pos
950 math-exp-token save-exp-token
951 math-expr-data save-exp-data
952 math-exp-pos save-exp-pos)))))))
953 (setq p (cdr p)))
954 (and p match)))
956 ;;;###autoload
957 (defun calc-match-user-syntax (p &optional term)
958 (let ((matches nil)
959 (save-exp-pos math-exp-pos)
960 (save-exp-old-pos math-exp-old-pos)
961 (save-exp-token math-exp-token)
962 (save-exp-data math-expr-data)
964 (while (and p
965 (cond ((stringp (car p))
966 (and (equal math-expr-data (car p))
967 (progn
968 (math-read-token)
969 t)))
970 ((integerp (car p))
971 (and (setq m (catch 'syntax
972 (math-read-expr-level
973 (car p)
974 (if (cdr p)
975 (if (consp (nth 1 p))
976 (car (nth 1 (nth 1 p)))
977 (nth 1 p))
978 term))))
979 (not (stringp m))
980 (setq matches (nconc matches (list m)))))
981 ((eq (car (car p)) '\?)
982 (setq m (calc-match-user-syntax (nth 1 (car p))))
983 (or (nth 2 (car p))
984 (setq matches
985 (nconc matches
986 (list
987 (cons 'vec (and (listp m) m))))))
988 (or (listp m) (not (nth 2 (car p)))
989 (not (eq (aref (car (nth 2 (car p))) 0) ?\$))
990 (eq math-exp-token 'end)))
992 (setq m (calc-match-user-syntax (nth 1 (car p))
993 (car (nth 2 (car p)))))
994 (if (listp m)
995 (let ((vec (cons 'vec m))
996 opos mm)
997 (while (and (listp
998 (setq opos math-exp-pos
999 mm (calc-match-user-syntax
1000 (or (nth 2 (car p))
1001 (nth 1 (car p)))
1002 (car (nth 2 (car p))))))
1003 (> math-exp-pos opos))
1004 (setq vec (nconc vec mm)))
1005 (setq matches (nconc matches (list vec))))
1006 (and (eq (car (car p)) '*)
1007 (setq matches (nconc matches (list '(vec)))))))))
1008 (setq p (cdr p)))
1009 (if p
1010 (setq math-exp-pos save-exp-pos
1011 math-exp-old-pos save-exp-old-pos
1012 math-exp-token save-exp-token
1013 math-expr-data save-exp-data
1014 matches "Failed"))
1015 matches))
1017 ;;;###autoload
1018 (defun math-remove-dashes (x)
1019 (if (string-match "\\`\\(.*\\)-\\(.*\\)\\'" x)
1020 (math-remove-dashes
1021 (concat (math-match-substring x 1) "#" (math-match-substring x 2)))
1024 (defun math-remove-percentsigns (x)
1025 (if (string-match "\\`\\(.*\\)%\\(.*\\)\\'" x)
1026 (math-remove-percentsigns
1027 (concat (math-match-substring x 1) "o'o" (math-match-substring x 2)))
1030 (defun math-restore-dashes (x)
1031 (if (string-match "\\`\\(.*\\)[#_]\\(.*\\)\\'" x)
1032 (math-restore-dashes
1033 (concat (math-match-substring x 1) "-" (math-match-substring x 2)))
1036 (defun math-restore-placeholders (x)
1037 "Replace placeholders by the proper characters in the symbol x.
1038 This includes `#' for `_' and `'' for `%'.
1039 If the current Calc language does not use placeholders, return nil."
1040 (if (or (memq calc-language calc-lang-allow-underscores)
1041 (memq calc-language calc-lang-allow-percentsigns))
1042 (let ((sx (symbol-name x)))
1043 (when (memq calc-language calc-lang-allow-percentsigns)
1044 (require 'calccomp)
1045 (setq sx (math-to-percentsigns sx)))
1046 (if (memq calc-language calc-lang-allow-underscores)
1047 (setq sx (math-string-restore-underscores sx)))
1048 (intern-soft sx))))
1050 (defun math-string-restore-underscores (x)
1051 "Replace pound signs by underscores in the string x."
1052 (if (string-match "\\`\\(.*\\)#\\(.*\\)\\'" x)
1053 (math-string-restore-underscores
1054 (concat (math-match-substring x 1) "_" (math-match-substring x 2)))
1057 ;;;###autoload
1058 (defun math-read-if (cond op)
1059 (let ((then (math-read-expr-level 0)))
1060 (or (equal math-expr-data ":")
1061 (throw 'syntax "Expected ':'"))
1062 (math-read-token)
1063 (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op)))))
1065 (defun math-factor-after ()
1066 (let ((math-exp-pos math-exp-pos)
1067 math-exp-old-pos math-exp-token math-expr-data)
1068 (math-read-token)
1069 (or (memq math-exp-token '(number symbol dollar hash string))
1070 (and (assoc math-expr-data '(("-") ("+") ("!") ("|") ("/")))
1071 (assoc (concat "u" math-expr-data) math-expr-opers))
1072 (eq (nth 2 (assoc math-expr-data math-expr-opers)) -1)
1073 (assoc math-expr-data '(("(") ("[") ("{"))))))
1075 (defun math-read-factor ()
1076 (let ((math-expr-opers (math-expr-ops))
1078 (cond ((eq math-exp-token 'number)
1079 (let ((num (math-read-number math-expr-data)))
1080 (if (not num)
1081 (progn
1082 (setq math-exp-old-pos math-exp-pos)
1083 (throw 'syntax "Bad format")))
1084 (math-read-token)
1085 (if (and math-read-expr-quotes
1086 (consp num))
1087 (list 'quote num)
1088 num)))
1089 ((and calc-user-parse-table
1090 (setq op (calc-check-user-syntax)))
1092 ((or (equal math-expr-data "-")
1093 (equal math-expr-data "+")
1094 (equal math-expr-data "!")
1095 (equal math-expr-data "|")
1096 (equal math-expr-data "/"))
1097 (setq math-expr-data (concat "u" math-expr-data))
1098 (math-read-factor))
1099 ((and (setq op (assoc math-expr-data math-expr-opers))
1100 (eq (nth 2 op) -1))
1101 (if (consp (nth 1 op))
1102 (funcall (car (nth 1 op)) op)
1103 (math-read-token)
1104 (let ((val (math-read-expr-level (nth 3 op))))
1105 (cond ((eq (nth 1 op) 'ident)
1106 val)
1107 ((and (Math-numberp val)
1108 (equal (car op) "u-"))
1109 (math-neg val))
1110 (t (list (nth 1 op) val))))))
1111 ((eq math-exp-token 'symbol)
1112 (let ((sym (intern math-expr-data)))
1113 (math-read-token)
1114 (if (equal math-expr-data calc-function-open)
1115 (let ((f (assq sym math-expr-function-mapping)))
1116 (math-read-token)
1117 (if (consp (cdr f))
1118 (funcall (car (cdr f)) f sym)
1119 (let ((args (if (or (equal math-expr-data calc-function-close)
1120 (eq math-exp-token 'end))
1122 (math-read-expr-list))))
1123 (if (not (or (equal math-expr-data calc-function-close)
1124 (eq math-exp-token 'end)))
1125 (throw 'syntax "Expected `)'"))
1126 (math-read-token)
1127 (if (and (memq calc-language
1128 calc-lang-parens-are-subscripts)
1129 args
1130 (require 'calc-ext)
1131 (let ((calc-matrix-mode 'scalar))
1132 (math-known-matrixp
1133 (list 'var sym
1134 (intern
1135 (concat "var-"
1136 (symbol-name sym)))))))
1137 (math-parse-fortran-subscr sym args)
1138 (if f
1139 (setq sym (cdr f))
1140 (and (= (aref (symbol-name sym) 0) ?\\)
1141 (< (prefix-numeric-value calc-language-option)
1143 (setq sym (intern (substring (symbol-name sym)
1144 1))))
1145 (or (string-match "-" (symbol-name sym))
1146 (setq sym (intern
1147 (concat "calcFunc-"
1148 (symbol-name sym))))))
1149 (cons sym args)))))
1150 (if math-read-expr-quotes
1152 (let ((val (list 'var
1153 (intern (math-remove-dashes
1154 (symbol-name sym)))
1155 (if (string-match "-" (symbol-name sym))
1157 (intern (concat "var-"
1158 (symbol-name sym)))))))
1159 (let ((v (or
1160 (assq (nth 1 val) math-expr-variable-mapping)
1161 (assq (math-restore-placeholders (nth 1 val))
1162 math-expr-variable-mapping))))
1163 (and v (setq val (if (consp (cdr v))
1164 (funcall (car (cdr v)) v val)
1165 (list 'var
1166 (intern
1167 (substring (symbol-name (cdr v))
1169 (cdr v))))))
1170 (while (and (memq calc-language
1171 calc-lang-brackets-are-subscripts)
1172 (equal math-expr-data "["))
1173 (math-read-token)
1174 (let ((el (math-read-expr-list)))
1175 (while el
1176 (setq val (append (list 'calcFunc-subscr val)
1177 (list (car el))))
1178 (setq el (cdr el))))
1179 (if (equal math-expr-data "]")
1180 (math-read-token)
1181 (throw 'syntax "Expected ']'")))
1182 val)))))
1183 ((eq math-exp-token 'dollar)
1184 (let ((abs (if (> math-expr-data 0) math-expr-data (- math-expr-data))))
1185 (if (>= (length calc-dollar-values) abs)
1186 (let ((num math-expr-data))
1187 (math-read-token)
1188 (setq calc-dollar-used (max calc-dollar-used num))
1189 (math-check-complete (nth (1- abs) calc-dollar-values)))
1190 (throw 'syntax (if calc-dollar-values
1191 "Too many $'s"
1192 "$'s not allowed in this context")))))
1193 ((eq math-exp-token 'hash)
1194 (or calc-hashes-used
1195 (throw 'syntax "#'s not allowed in this context"))
1196 (require 'calc-ext)
1197 (if (<= math-expr-data (length calc-arg-values))
1198 (let ((num math-expr-data))
1199 (math-read-token)
1200 (setq calc-hashes-used (max calc-hashes-used num))
1201 (nth (1- num) calc-arg-values))
1202 (throw 'syntax "Too many # arguments")))
1203 ((equal math-expr-data "(")
1204 (let* ((exp (let ((math-exp-keep-spaces nil))
1205 (math-read-token)
1206 (if (or (equal math-expr-data "\\dots")
1207 (equal math-expr-data "\\ldots"))
1208 '(neg (var inf var-inf))
1209 (math-read-expr-level 0)))))
1210 (let ((math-exp-keep-spaces nil))
1211 (cond
1212 ((equal math-expr-data ",")
1213 (progn
1214 (math-read-token)
1215 (let ((exp2 (math-read-expr-level 0)))
1216 (setq exp
1217 (if (and exp2 (Math-realp exp) (Math-realp exp2))
1218 (math-normalize (list 'cplx exp exp2))
1219 (list '+ exp (list '* exp2 '(var i var-i))))))))
1220 ((equal math-expr-data ";")
1221 (progn
1222 (math-read-token)
1223 (let ((exp2 (math-read-expr-level 0)))
1224 (setq exp (if (and exp2 (Math-realp exp)
1225 (Math-anglep exp2))
1226 (math-normalize (list 'polar exp exp2))
1227 (require 'calc-ext)
1228 (list '* exp
1229 (list 'calcFunc-exp
1230 (list '*
1231 (math-to-radians-2 exp2)
1232 '(var i var-i)))))))))
1233 ((or (equal math-expr-data "\\dots")
1234 (equal math-expr-data "\\ldots"))
1235 (progn
1236 (math-read-token)
1237 (let ((exp2 (if (or (equal math-expr-data ")")
1238 (equal math-expr-data "]")
1239 (eq math-exp-token 'end))
1240 '(var inf var-inf)
1241 (math-read-expr-level 0))))
1242 (setq exp
1243 (list 'intv
1244 (if (equal math-expr-data ")") 0 1)
1246 exp2)))))))
1247 (if (not (or (equal math-expr-data ")")
1248 (and (equal math-expr-data "]") (eq (car-safe exp) 'intv))
1249 (eq math-exp-token 'end)))
1250 (throw 'syntax "Expected `)'"))
1251 (math-read-token)
1252 exp))
1253 ((eq math-exp-token 'string)
1254 (require 'calc-ext)
1255 (math-read-string))
1256 ((equal math-expr-data "[")
1257 (require 'calc-ext)
1258 (math-read-brackets t "]"))
1259 ((equal math-expr-data "{")
1260 (require 'calc-ext)
1261 (math-read-brackets nil "}"))
1262 ((equal math-expr-data "<")
1263 (require 'calc-ext)
1264 (math-read-angle-brackets))
1265 (t (throw 'syntax "Expected a number")))))
1267 (provide 'calc-aent)
1269 ;; Local variables:
1270 ;; coding: utf-8
1271 ;; generated-autoload-file: "calc-loaddefs.el"
1272 ;; End:
1274 ;;; calc-aent.el ends here