Use list for the tags completion table, not obarray
[emacs.git] / lisp / calc / calc-aent.el
blobcc048ebc223c856f58631d05749056c605e0ea39
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-refresh-evaltos "calc-ext" (&optional which-var))
34 (declare-function calc-execute-kbd-macro "calc-prog" (mac arg &rest prefix))
35 (declare-function math-is-true "calc-ext" (expr))
36 (declare-function calc-explain-why "calc-stuff" (why &optional more))
37 (declare-function calc-alg-edit "calc-yank" (str))
38 (declare-function math-composite-inequalities "calc-prog" (x op))
39 (declare-function math-flatten-lands "calc-rewr" (expr))
40 (declare-function math-multi-subst "calc-map" (expr olds news))
41 (declare-function calcFunc-vmatches "calc-rewr" (expr pat))
42 (declare-function math-simplify "calc-alg" (top-expr))
43 (declare-function math-known-matrixp "calc-arith" (a))
44 (declare-function math-parse-fortran-subscr "calc-lang" (sym args))
45 (declare-function math-to-radians-2 "calc-math" (a &optional force-symbolic))
46 (declare-function math-read-string "calc-ext" ())
47 (declare-function math-read-brackets "calc-vec" (space-sep math-rb-close))
48 (declare-function math-read-angle-brackets "calc-forms" ())
49 (declare-function math-to-percentsigns "calccomp" (x))
51 (defvar calc-quick-calc-history nil
52 "The history list for quick-calc.")
54 ;;;###autoload
55 (defun calc-do-quick-calc (&optional insert)
56 (require 'calc-ext)
57 (calc-check-defines)
58 (if (eq major-mode 'calc-mode)
59 (calc-algebraic-entry t)
60 (let (buf shortbuf)
61 (save-excursion
62 (calc-create-buffer)
63 (let* ((calc-command-flags nil)
64 (calc-dollar-values calc-quick-prev-results)
65 (calc-dollar-used 0)
66 (enable-recursive-minibuffers t)
67 (calc-language (if (memq calc-language '(nil big))
68 'flat calc-language))
69 (entry (calc-do-alg-entry "" "Quick calc: " t 'calc-quick-calc-history))
70 (alg-exp (mapcar 'math-evaluate-expr entry)))
71 (when (and (= (length alg-exp) 1)
72 (eq (car-safe (car alg-exp)) 'calcFunc-assign)
73 (= (length (car alg-exp)) 3)
74 (eq (car-safe (nth 1 (car alg-exp))) 'var))
75 (set (nth 2 (nth 1 (car alg-exp))) (nth 2 (car alg-exp)))
76 (calc-refresh-evaltos (nth 2 (nth 1 (car alg-exp))))
77 (setq alg-exp (list (nth 2 (car alg-exp)))))
78 (setq calc-quick-prev-results alg-exp
79 buf (mapconcat (function (lambda (x)
80 (math-format-value x 1000)))
81 alg-exp
82 " ")
83 shortbuf buf)
84 (if (and (= (length alg-exp) 1)
85 (memq (car-safe (car alg-exp)) '(nil bigpos bigneg))
86 (< (length buf) 20)
87 (= calc-number-radix 10))
88 (setq buf (concat buf " ("
89 (let ((calc-number-radix 16))
90 (math-format-value (car alg-exp) 1000))
91 ", "
92 (let ((calc-number-radix 8))
93 (math-format-value (car alg-exp) 1000))
94 ", "
95 (let ((calc-number-radix 2))
96 (math-format-value (car alg-exp) 1000))
97 (if (and (integerp (car alg-exp))
98 (> (car alg-exp) 0)
99 (< (car alg-exp) 127))
100 (format ", \"%c\"" (car alg-exp))
102 ")")))
103 (if (and (< (length buf) (frame-width)) (= (length entry) 1)
104 (featurep 'calc-ext))
105 (let ((long (concat (math-format-value (car entry) 1000)
106 " => " buf)))
107 (if (<= (length long) (- (frame-width) 8))
108 (setq buf long))))
109 (calc-handle-whys)
110 (message "Result: %s" buf)))
111 (if (or insert
112 (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* ((calc-dollar-values (mapcar #'calc-get-stack-element
291 (nthcdr calc-stack-top calc-stack)))
292 (calc-dollar-used 0)
293 (calc-plain-entry t)
294 (alg-exp (calc-do-alg-entry initial prompt t 'calc-alg-entry-history)))
295 (if (stringp alg-exp)
296 (progn
297 (require 'calc-ext)
298 (calc-alg-edit alg-exp))
299 (let* ((calc-simplify-mode (if (eq last-command-event ?\C-j)
300 'none
301 calc-simplify-mode))
302 (nvals (mapcar 'calc-normalize alg-exp)))
303 (while alg-exp
304 (calc-record (if (featurep 'calc-ext) (car alg-exp) (car nvals))
305 "alg'")
306 (calc-pop-push-record-list calc-dollar-used
307 (and (not (equal (car alg-exp)
308 (car nvals)))
309 (featurep 'calc-ext)
311 (list (car nvals)))
312 (setq alg-exp (cdr alg-exp)
313 nvals (cdr nvals)
314 calc-dollar-used 0)))
315 (calc-handle-whys))))
317 (defvar calc-alg-ent-map
318 (let ((map (make-sparse-keymap)))
319 (set-keymap-parent map minibuffer-local-map)
320 (define-key map "'" 'calcAlg-previous)
321 (define-key map "`" 'calcAlg-edit)
322 (define-key map "\C-m" 'calcAlg-enter)
323 (define-key map "\C-j" 'calcAlg-enter)
324 map)
325 "The keymap used for algebraic entry.")
327 (defvar calc-alg-ent-esc-map
328 (let ((map (make-keymap))
329 (i 33))
330 (set-keymap-parent map esc-map)
331 (while (< i 127)
332 (define-key map (vector i) 'calcAlg-escape)
333 (setq i (1+ i)))
334 map)
335 "The keymap used for escapes in algebraic entry.")
337 (defvar calc-alg-exp)
339 ;;;###autoload
340 (defun calc-do-alg-entry (&optional initial prompt no-normalize history)
341 (let* ((calc-buffer (current-buffer))
342 (blink-matching-check-function 'calcAlg-blink-matching-check)
343 (calc-alg-exp 'error))
344 (define-key calc-alg-ent-map "\e" nil)
345 (if (eq calc-algebraic-mode 'total)
346 (define-key calc-alg-ent-map "\e" calc-alg-ent-esc-map)
347 (define-key calc-alg-ent-map "\e+" 'calcAlg-plus-minus)
348 (define-key calc-alg-ent-map "\em" 'calcAlg-mod)
349 (define-key calc-alg-ent-map "\e=" 'calcAlg-equals)
350 (define-key calc-alg-ent-map "\e\r" 'calcAlg-equals)
351 (define-key calc-alg-ent-map "\ep" 'previous-history-element)
352 (define-key calc-alg-ent-map "\en" 'next-history-element)
353 (define-key calc-alg-ent-map "\e%" 'self-insert-command))
354 (setq calc-aborted-prefix nil)
355 (let ((buf (read-from-minibuffer (or prompt "Algebraic: ")
356 (or initial "")
357 calc-alg-ent-map nil history)))
358 (when (eq calc-alg-exp 'error)
359 (when (eq (car-safe (setq calc-alg-exp (math-read-exprs buf))) 'error)
360 (setq calc-alg-exp nil)))
361 (setq calc-aborted-prefix "alg'")
362 (or no-normalize
363 (and calc-alg-exp (setq calc-alg-exp (mapcar 'calc-normalize calc-alg-exp))))
364 calc-alg-exp)))
366 (defun calcAlg-plus-minus ()
367 (interactive)
368 (if (calc-minibuffer-contains ".* \\'")
369 (insert "+/- ")
370 (insert " +/- ")))
372 (defun calcAlg-mod ()
373 (interactive)
374 (if (not (calc-minibuffer-contains ".* \\'"))
375 (insert " "))
376 (if (calc-minibuffer-contains ".* mod +\\'")
377 (if calc-previous-modulo
378 (insert (math-format-flat-expr calc-previous-modulo 0))
379 (beep))
380 (insert "mod ")))
382 (defun calcAlg-previous ()
383 (interactive)
384 (if (calc-minibuffer-contains "\\'")
385 (previous-history-element 1)
386 (insert "'")))
388 (defun calcAlg-equals ()
389 (interactive)
390 (unwind-protect
391 (calcAlg-enter)
392 (if (consp calc-alg-exp)
393 (progn (setq prefix-arg (length calc-alg-exp))
394 (calc-unread-command ?=)))))
396 (defun calcAlg-escape ()
397 (interactive)
398 (calc-unread-command)
399 (save-excursion
400 (calc-select-buffer)
401 (use-local-map calc-mode-map))
402 (calcAlg-enter))
404 (defvar calc-plain-entry nil)
405 (defun calcAlg-edit ()
406 (interactive)
407 (if (or (not calc-plain-entry)
408 (calc-minibuffer-contains
409 "\\`\\([^\"]*\"[^\"]*\"\\)*[^\"]*\"[^\"]*\\'"))
410 (insert "`")
411 (setq calc-alg-exp (minibuffer-contents))
412 (exit-minibuffer)))
414 (defvar calc-buffer)
416 (defun calcAlg-enter ()
417 (interactive)
418 (let* ((str (minibuffer-contents))
419 (exp (and (> (length str) 0)
420 (with-current-buffer calc-buffer
421 (math-read-exprs str)))))
422 (if (eq (car-safe exp) 'error)
423 (progn
424 (goto-char (minibuffer-prompt-end))
425 (forward-char (nth 1 exp))
426 (beep)
427 (calc-temp-minibuffer-message
428 (concat " [" (or (nth 2 exp) "Error") "]"))
429 (calc-clear-unread-commands))
430 (setq calc-alg-exp (if (calc-minibuffer-contains "\\` *\\[ *\\'")
431 '((incomplete vec))
432 exp))
433 (exit-minibuffer))))
435 (defun calcAlg-blink-matching-check (leftpt rightpt)
436 (let ((rightchar (char-before rightpt))
437 (leftchar (if leftpt (char-after leftpt))))
438 (if (and leftpt
439 (or (and (= rightchar ?\))
440 (= leftchar ?\[))
441 (and (= rightchar ?\])
442 (= leftchar ?\()))
443 (save-excursion
444 (goto-char leftpt)
445 (looking-at ".+\\(\\.\\.\\|\\\\dots\\|\\\\ldots\\)")))
446 ;; [2..5) perfectly valid!
448 (blink-matching-check-mismatch leftpt rightpt))))
450 ;;;###autoload
451 (defun calc-alg-digit-entry ()
452 (calc-alg-entry
453 (cond ((eq last-command-event ?e)
454 (if (> calc-number-radix 14) (format "%d.^" calc-number-radix) "1e"))
455 ((eq last-command-event ?#) (format "%d#" calc-number-radix))
456 ((eq last-command-event ?_) "-")
457 ((eq last-command-event ?@) "0@ ")
458 (t (char-to-string last-command-event)))))
460 ;; The variable calc-digit-value is initially declared in calc.el,
461 ;; but can be set by calcDigit-algebraic and calcDigit-edit.
462 (defvar calc-digit-value)
464 ;;;###autoload
465 (defun calcDigit-algebraic ()
466 (interactive)
467 (if (calc-minibuffer-contains ".*[@oh] *[^'m ]+[^'m]*\\'")
468 (calcDigit-key)
469 (setq calc-digit-value (minibuffer-contents))
470 (exit-minibuffer)))
472 ;;;###autoload
473 (defun calcDigit-edit ()
474 (interactive)
475 (calc-unread-command)
476 (setq calc-digit-value (minibuffer-contents))
477 (exit-minibuffer))
480 ;;; Algebraic expression parsing. [Public]
482 (defvar math-read-replacement-list
483 '(;; Misc symbols
484 ("±" "+/-") ; plus or minus
485 ("×" "*") ; multiplication sign
486 ("÷" ":") ; division sign
487 ("−" "-") ; subtraction sign
488 ("∕" "/") ; division sign
489 ("∗" "*") ; asterisk multiplication
490 ("∞" "inf") ; infinity symbol
491 ("≤" "<=")
492 ("≥" ">=")
493 ("≦" "<=")
494 ("≧" ">=")
495 ("µ" "μ")
496 ;; fractions
497 ("¼" "(1:4)") ; 1/4
498 ("½" "(1:2)") ; 1/2
499 ("¾" "(3:4)") ; 3/4
500 ("⅓" "(1:3)") ; 1/3
501 ("⅔" "(2:3)") ; 2/3
502 ("⅕" "(1:5)") ; 1/5
503 ("⅖" "(2:5)") ; 2/5
504 ("⅗" "(3:5)") ; 3/5
505 ("⅘" "(4:5)") ; 4/5
506 ("⅙" "(1:6)") ; 1/6
507 ("⅚" "(5:6)") ; 5/6
508 ("⅛" "(1:8)") ; 1/8
509 ("⅜" "(3:8)") ; 3/8
510 ("⅝" "(5:8)") ; 5/8
511 ("⅞" "(7:8)") ; 7/8
512 ("⅟" "1:") ; 1/...
513 ;; superscripts
514 ("⁰" "0") ; 0
515 ("¹" "1") ; 1
516 ("²" "2") ; 2
517 ("³" "3") ; 3
518 ("⁴" "4") ; 4
519 ("⁵" "5") ; 5
520 ("⁶" "6") ; 6
521 ("⁷" "7") ; 7
522 ("⁸" "8") ; 8
523 ("⁹" "9") ; 9
524 ("⁺" "+") ; +
525 ("⁻" "-") ; -
526 ("⁽" "(") ; (
527 ("⁾" ")") ; )
528 ("ⁿ" "n") ; n
529 ("ⁱ" "i") ; i
530 ;; subscripts
531 ("₀" "0") ; 0
532 ("₁" "1") ; 1
533 ("₂" "2") ; 2
534 ("₃" "3") ; 3
535 ("₄" "4") ; 4
536 ("₅" "5") ; 5
537 ("₆" "6") ; 6
538 ("₇" "7") ; 7
539 ("₈" "8") ; 8
540 ("₉" "9") ; 9
541 ("₊" "+") ; +
542 ("₋" "-") ; -
543 ("₍" "(") ; (
544 ("₎" ")")) ; )
545 "A list whose elements (old new) indicate replacements to make
546 in Calc algebraic input.")
548 (defvar math-read-superscripts
549 "⁰¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁽⁾ⁿⁱ" ; 0123456789+-()ni
550 "A string consisting of the superscripts allowed by Calc.")
552 (defvar math-read-subscripts
553 "₀₁₂₃₄₅₆₇₈₉₊₋₍₎" ; 0123456789+-()
554 "A string consisting of the subscripts allowed by Calc.")
556 ;;;###autoload
557 (defun math-read-preprocess-string (str)
558 "Replace some substrings of STR by Calc equivalents."
559 (setq str
560 (replace-regexp-in-string (concat "[" math-read-superscripts "]+")
561 "^(\\&)" str))
562 (setq str
563 (replace-regexp-in-string (concat "[" math-read-subscripts "]+")
564 "_(\\&)" str))
565 (let ((rep-list math-read-replacement-list))
566 (while rep-list
567 (setq str
568 (replace-regexp-in-string (nth 0 (car rep-list))
569 (nth 1 (car rep-list)) str))
570 (setq rep-list (cdr rep-list))))
571 str)
573 ;; The next few variables are local to math-read-exprs (and math-read-expr
574 ;; in calc-ext.el), but are set in functions they call.
576 (defvar math-exp-pos)
577 (defvar math-exp-str)
578 (defvar math-exp-old-pos)
579 (defvar math-exp-token)
580 (defvar math-exp-keep-spaces)
581 (defvar math-expr-data)
583 ;;;###autoload
584 (defun math-read-exprs (math-exp-str)
585 (let ((math-exp-pos 0)
586 (math-exp-old-pos 0)
587 (math-exp-keep-spaces nil)
588 math-exp-token math-expr-data)
589 (setq math-exp-str (math-read-preprocess-string math-exp-str))
590 (if (memq calc-language calc-lang-allow-percentsigns)
591 (setq math-exp-str (math-remove-percentsigns math-exp-str)))
592 (if calc-language-input-filter
593 (setq math-exp-str (funcall calc-language-input-filter math-exp-str)))
594 (while (setq math-exp-token
595 (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str))
596 (setq math-exp-str
597 (concat (substring math-exp-str 0 math-exp-token) "\\dots"
598 (substring math-exp-str (+ math-exp-token 2)))))
599 (math-build-parse-table)
600 (math-read-token)
601 (let ((val (catch 'syntax (math-read-expr-list))))
602 (if (stringp val)
603 (list 'error math-exp-old-pos val)
604 (if (equal math-exp-token 'end)
606 (list 'error math-exp-old-pos "Syntax error"))))))
608 ;;;###autoload
609 (defun math-read-expr-list ()
610 (let* ((math-exp-keep-spaces nil)
611 (val (list (math-read-expr-level 0)))
612 (last val))
613 (while (equal math-expr-data ",")
614 (math-read-token)
615 (let ((rest (list (math-read-expr-level 0))))
616 (setcdr last rest)
617 (setq last rest)))
618 val))
620 (defvar calc-user-parse-table nil)
621 (defvar calc-last-main-parse-table nil)
622 (defvar calc-last-user-lang-parse-table nil)
623 (defvar calc-last-lang-parse-table nil)
624 (defvar calc-user-tokens nil)
625 (defvar calc-user-token-chars nil)
627 (defvar math-toks nil
628 "Tokens to pass between math-build-parse-table and math-find-user-tokens.")
630 ;;;###autoload
631 (defun math-build-parse-table ()
632 (let ((mtab (cdr (assq nil calc-user-parse-tables)))
633 (ltab (cdr (assq calc-language calc-user-parse-tables)))
634 (lltab (get calc-language 'math-parse-table)))
635 (or (and (eq mtab calc-last-main-parse-table)
636 (eq ltab calc-last-user-lang-parse-table)
637 (eq lltab calc-last-lang-parse-table))
638 (let ((p (append mtab ltab lltab))
639 (math-toks nil))
640 (setq calc-user-parse-table p)
641 (setq calc-user-token-chars nil)
642 (while p
643 (math-find-user-tokens (car (car p)))
644 (setq p (cdr p)))
645 (setq calc-user-tokens (mapconcat 'identity
646 (sort (mapcar 'car math-toks)
647 (function (lambda (x y)
648 (> (length x)
649 (length y)))))
650 "\\|")
651 calc-last-main-parse-table mtab
652 calc-last-user-lang-parse-table ltab
653 calc-last-lang-parse-table lltab)))))
655 ;;;###autoload
656 (defun math-find-user-tokens (p)
657 (while p
658 (cond ((and (stringp (car p))
659 (or (> (length (car p)) 1) (equal (car p) "$")
660 (equal (car p) "\""))
661 (string-match "[^a-zA-Zα-ωΑ-Ω0-9]" (car p)))
662 (let ((s (regexp-quote (car p))))
663 (if (string-match "\\`[a-zA-Zα-ωΑ-Ω0-9]" s)
664 (setq s (concat "\\<" s)))
665 (if (string-match "[a-zA-Zα-ωΑ-Ω0-9]\\'" s)
666 (setq s (concat s "\\>")))
667 (or (assoc s math-toks)
668 (progn
669 (setq math-toks (cons (list s) math-toks))
670 (or (memq (aref (car p) 0) calc-user-token-chars)
671 (setq calc-user-token-chars
672 (cons (aref (car p) 0)
673 calc-user-token-chars)))))))
674 ((consp (car p))
675 (math-find-user-tokens (nth 1 (car p)))
676 (or (eq (car (car p)) '\?)
677 (math-find-user-tokens (nth 2 (car p))))))
678 (setq p (cdr p))))
680 ;;;###autoload
681 (defun math-read-token ()
682 (if (>= math-exp-pos (length math-exp-str))
683 (setq math-exp-old-pos math-exp-pos
684 math-exp-token 'end
685 math-expr-data "\000")
686 (let (adfn
687 (ch (aref math-exp-str math-exp-pos)))
688 (setq math-exp-old-pos math-exp-pos)
689 (cond ((memq ch '(32 10 9))
690 (setq math-exp-pos (1+ math-exp-pos))
691 (if math-exp-keep-spaces
692 (setq math-exp-token 'space
693 math-expr-data " ")
694 (math-read-token)))
695 ((and (memq ch calc-user-token-chars)
696 (let ((case-fold-search nil))
697 (eq (string-match
698 calc-user-tokens math-exp-str math-exp-pos)
699 math-exp-pos)))
700 (setq math-exp-token 'punc
701 math-expr-data (math-match-substring math-exp-str 0)
702 math-exp-pos (match-end 0)))
703 ((or (and (>= ch ?a) (<= ch ?z))
704 (and (>= ch ?A) (<= ch ?Z))
705 (and (>= ch ?α) (<= ch ?ω))
706 (and (>= ch ?Α) (<= ch ?Ω)))
707 (string-match
708 (cond
709 ((and (memq calc-language calc-lang-allow-underscores)
710 (memq calc-language calc-lang-allow-percentsigns))
711 "[a-zA-Zα-ωΑ-Ω0-9_'#]*")
712 ((memq calc-language calc-lang-allow-underscores)
713 "[a-zA-Zα-ωΑ-Ω0-9_#]*")
714 (t "[a-zA-Zα-ωΑ-Ω0-9'#]*"))
715 math-exp-str math-exp-pos)
716 (setq math-exp-token 'symbol
717 math-exp-pos (match-end 0)
718 math-expr-data (math-restore-dashes
719 (math-match-substring math-exp-str 0)))
720 (if (setq adfn (get calc-language 'math-lang-adjust-words))
721 (funcall adfn)))
722 ((or (and (>= ch ?0) (<= ch ?9))
723 (and (eq ch '?\.)
724 (eq (string-match "\\.[0-9]" math-exp-str math-exp-pos)
725 math-exp-pos))
726 (and (eq ch '?_)
727 (eq (string-match "_\\.?[0-9]" math-exp-str math-exp-pos)
728 math-exp-pos)
729 (or (eq math-exp-pos 0)
730 (and (not (memq calc-language
731 calc-lang-allow-underscores))
732 (eq (string-match "[^])}\"a-zA-Zα-ωΑ-Ω0-9'$]_"
733 math-exp-str (1- math-exp-pos))
734 (1- math-exp-pos))))))
735 (or (and (memq calc-language calc-lang-c-type-hex)
736 (string-match "0[xX][0-9a-fA-F]+" math-exp-str math-exp-pos))
737 (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]+\\)?\"?\\)?"
738 math-exp-str math-exp-pos))
739 (setq math-exp-token 'number
740 math-expr-data (math-match-substring math-exp-str 0)
741 math-exp-pos (match-end 0)))
742 ((and (setq adfn
743 (assq ch (get calc-language 'math-lang-read-symbol)))
744 (eval (nth 1 adfn)))
745 (eval (nth 2 adfn)))
746 ((eq ch ?\$)
747 (if (eq (string-match "\\$\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
748 math-exp-pos)
749 (setq math-expr-data (- (string-to-number (math-match-substring
750 math-exp-str 1))))
751 (string-match "\\$+" math-exp-str math-exp-pos)
752 (setq math-expr-data (- (match-end 0) (match-beginning 0))))
753 (setq math-exp-token 'dollar
754 math-exp-pos (match-end 0)))
755 ((eq ch ?\#)
756 (if (eq (string-match "#\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
757 math-exp-pos)
758 (setq math-expr-data (string-to-number
759 (math-match-substring math-exp-str 1))
760 math-exp-pos (match-end 0))
761 (setq math-expr-data 1
762 math-exp-pos (1+ math-exp-pos)))
763 (setq math-exp-token 'hash))
764 ((eq (string-match "~=\\|<=\\|>=\\|<>\\|/=\\|\\+/-\\|\\\\dots\\|\\\\ldots\\|\\*\\*\\|<<\\|>>\\|==\\|!=\\|&&&\\||||\\|!!!\\|&&\\|||\\|!!\\|:=\\|::\\|=>"
765 math-exp-str math-exp-pos)
766 math-exp-pos)
767 (setq math-exp-token 'punc
768 math-expr-data (math-match-substring math-exp-str 0)
769 math-exp-pos (match-end 0)))
770 ((and (eq ch ?\")
771 (string-match "\\(\"\\([^\"\\]\\|\\\\.\\)*\\)\\(\"\\|\\'\\)"
772 math-exp-str math-exp-pos))
773 (setq math-exp-token 'string
774 math-expr-data (math-match-substring math-exp-str 1)
775 math-exp-pos (match-end 0)))
776 ((and (setq adfn (get calc-language 'math-lang-read))
777 (eval (nth 0 adfn))
778 (eval (nth 1 adfn))))
779 ((eq (string-match "%%.*$" math-exp-str math-exp-pos) math-exp-pos)
780 (setq math-exp-pos (match-end 0))
781 (math-read-token))
783 (if (setq adfn (assq ch (get calc-language 'math-punc-table)))
784 (setq ch (cdr adfn)))
785 (setq math-exp-token 'punc
786 math-expr-data (char-to-string ch)
787 math-exp-pos (1+ math-exp-pos)))))))
789 (defconst math-alg-inequalities
790 '(calcFunc-lt calcFunc-gt calcFunc-leq calcFunc-geq
791 calcFunc-eq calcFunc-neq))
793 (defun math-read-expr-level (exp-prec &optional exp-term)
794 (let* ((math-expr-opers (math-expr-ops))
795 (x (math-read-factor))
796 (first t)
797 op op2)
798 (while (and (or (and calc-user-parse-table
799 (setq op (calc-check-user-syntax x exp-prec))
800 (setq x op
801 op '("2x" ident 999999 -1)))
802 (and (setq op (assoc math-expr-data math-expr-opers))
803 (/= (nth 2 op) -1)
804 (or (and (setq op2 (assoc
805 math-expr-data
806 (cdr (memq op math-expr-opers))))
807 (eq (= (nth 3 op) -1)
808 (/= (nth 3 op2) -1))
809 (eq (= (nth 3 op2) -1)
810 (not (math-factor-after)))
811 (setq op op2))
813 (and (or (eq (nth 2 op) -1)
814 (memq math-exp-token '(symbol number dollar hash))
815 (equal math-expr-data "(")
816 (and (equal math-expr-data "[")
817 (not (equal
818 (get calc-language
819 'math-function-open) "["))
820 (not (and math-exp-keep-spaces
821 (eq (car-safe x) 'vec)))))
822 (or (not (setq op (assoc math-expr-data math-expr-opers)))
823 (/= (nth 2 op) -1))
824 (or (not calc-user-parse-table)
825 (not (eq math-exp-token 'symbol))
826 (let ((p calc-user-parse-table))
827 (while (and p
828 (or (not (integerp
829 (car (car (car p)))))
830 (not (equal
831 (nth 1 (car (car p)))
832 math-expr-data))))
833 (setq p (cdr p)))
834 (not p)))
835 (setq op (assoc "2x" math-expr-opers))))
836 (not (and exp-term (equal math-expr-data exp-term)))
837 (>= (nth 2 op) exp-prec))
838 (if (not (equal (car op) "2x"))
839 (math-read-token))
840 (and (memq (nth 1 op) '(sdev mod))
841 (require 'calc-ext))
842 (setq x (cond ((consp (nth 1 op))
843 (funcall (car (nth 1 op)) x op))
844 ((eq (nth 3 op) -1)
845 (if (eq (nth 1 op) 'ident)
847 (if (eq (nth 1 op) 'closing)
848 (if (eq (nth 2 op) exp-prec)
849 (progn
850 (setq exp-prec 1000)
852 (throw 'syntax "Mismatched delimiters"))
853 (list (nth 1 op) x))))
854 ((and (not first)
855 (memq (nth 1 op) math-alg-inequalities)
856 (memq (car-safe x) math-alg-inequalities))
857 (require 'calc-ext)
858 (math-composite-inequalities x op))
859 (t (list (nth 1 op)
861 (math-read-expr-level (nth 3 op) exp-term))))
862 first nil))
865 ;; calc-arg-values is defined in calc-ext.el, but is used here.
866 (defvar calc-arg-values)
868 ;;;###autoload
869 (defun calc-check-user-syntax (&optional x prec)
870 (let ((p calc-user-parse-table)
871 (matches nil)
872 match rule)
873 (while (and p
874 (or (not (progn
875 (setq rule (car (car p)))
876 (if x
877 (and (integerp (car rule))
878 (>= (car rule) prec)
879 (equal math-expr-data
880 (car (setq rule (cdr rule)))))
881 (equal math-expr-data (car rule)))))
882 (let ((save-exp-pos math-exp-pos)
883 (save-exp-old-pos math-exp-old-pos)
884 (save-exp-token math-exp-token)
885 (save-exp-data math-expr-data))
886 (or (not (listp
887 (setq matches (calc-match-user-syntax rule))))
888 (let ((args (progn
889 (require 'calc-ext)
890 calc-arg-values))
891 (conds nil)
892 temp)
893 (if x
894 (setq matches (cons x matches)))
895 (setq match (cdr (car p)))
896 (while (and (eq (car-safe match)
897 'calcFunc-condition)
898 (= (length match) 3))
899 (setq conds (append (math-flatten-lands
900 (nth 2 match))
901 conds)
902 match (nth 1 match)))
903 (while (and conds match)
904 (require 'calc-ext)
905 (cond ((eq (car-safe (car conds))
906 'calcFunc-let)
907 (setq temp (car conds))
908 (or (= (length temp) 3)
909 (and (= (length temp) 2)
910 (eq (car-safe (nth 1 temp))
911 'calcFunc-assign)
912 (= (length (nth 1 temp)) 3)
913 (setq temp (nth 1 temp)))
914 (setq match nil))
915 (setq matches (cons
916 (math-normalize
917 (math-multi-subst
918 (nth 2 temp)
919 args matches))
920 matches)
921 args (cons (nth 1 temp)
922 args)))
923 ((and (eq (car-safe (car conds))
924 'calcFunc-matches)
925 (= (length (car conds)) 3))
926 (setq temp (calcFunc-vmatches
927 (math-multi-subst
928 (nth 1 (car conds))
929 args matches)
930 (nth 2 (car conds))))
931 (if (eq temp 0)
932 (setq match nil)
933 (while (setq temp (cdr temp))
934 (setq matches (cons (nth 2 (car temp))
935 matches)
936 args (cons (nth 1 (car temp))
937 args)))))
939 (or (math-is-true (math-simplify
940 (math-multi-subst
941 (car conds)
942 args matches)))
943 (setq match nil))))
944 (setq conds (cdr conds)))
945 (if match
946 (not (setq match (math-multi-subst
947 match args matches)))
948 (setq math-exp-old-pos save-exp-old-pos
949 math-exp-token save-exp-token
950 math-expr-data save-exp-data
951 math-exp-pos save-exp-pos)))))))
952 (setq p (cdr p)))
953 (and p match)))
955 ;;;###autoload
956 (defun calc-match-user-syntax (p &optional term)
957 (let ((matches nil)
958 (save-exp-pos math-exp-pos)
959 (save-exp-old-pos math-exp-old-pos)
960 (save-exp-token math-exp-token)
961 (save-exp-data math-expr-data)
963 (while (and p
964 (cond ((stringp (car p))
965 (and (equal math-expr-data (car p))
966 (progn
967 (math-read-token)
968 t)))
969 ((integerp (car p))
970 (and (setq m (catch 'syntax
971 (math-read-expr-level
972 (car p)
973 (if (cdr p)
974 (if (consp (nth 1 p))
975 (car (nth 1 (nth 1 p)))
976 (nth 1 p))
977 term))))
978 (not (stringp m))
979 (setq matches (nconc matches (list m)))))
980 ((eq (car (car p)) '\?)
981 (setq m (calc-match-user-syntax (nth 1 (car p))))
982 (or (nth 2 (car p))
983 (setq matches
984 (nconc matches
985 (list
986 (cons 'vec (and (listp m) m))))))
987 (or (listp m) (not (nth 2 (car p)))
988 (not (eq (aref (car (nth 2 (car p))) 0) ?\$))
989 (eq math-exp-token 'end)))
991 (setq m (calc-match-user-syntax (nth 1 (car p))
992 (car (nth 2 (car p)))))
993 (if (listp m)
994 (let ((vec (cons 'vec m))
995 opos mm)
996 (while (and (listp
997 (setq opos math-exp-pos
998 mm (calc-match-user-syntax
999 (or (nth 2 (car p))
1000 (nth 1 (car p)))
1001 (car (nth 2 (car p))))))
1002 (> math-exp-pos opos))
1003 (setq vec (nconc vec mm)))
1004 (setq matches (nconc matches (list vec))))
1005 (and (eq (car (car p)) '*)
1006 (setq matches (nconc matches (list '(vec)))))))))
1007 (setq p (cdr p)))
1008 (if p
1009 (setq math-exp-pos save-exp-pos
1010 math-exp-old-pos save-exp-old-pos
1011 math-exp-token save-exp-token
1012 math-expr-data save-exp-data
1013 matches "Failed"))
1014 matches))
1016 ;;;###autoload
1017 (defun math-remove-dashes (x)
1018 (if (string-match "\\`\\(.*\\)-\\(.*\\)\\'" x)
1019 (math-remove-dashes
1020 (concat (math-match-substring x 1) "#" (math-match-substring x 2)))
1023 (defun math-remove-percentsigns (x)
1024 (if (string-match "\\`\\(.*\\)%\\(.*\\)\\'" x)
1025 (math-remove-percentsigns
1026 (concat (math-match-substring x 1) "o'o" (math-match-substring x 2)))
1029 (defun math-restore-dashes (x)
1030 (if (string-match "\\`\\(.*\\)[#_]\\(.*\\)\\'" x)
1031 (math-restore-dashes
1032 (concat (math-match-substring x 1) "-" (math-match-substring x 2)))
1035 (defun math-restore-placeholders (x)
1036 "Replace placeholders by the proper characters in the symbol x.
1037 This includes ‘#’ for ‘_’ and ‘'’ for ‘%’.
1038 If the current Calc language does not use placeholders, return nil."
1039 (if (or (memq calc-language calc-lang-allow-underscores)
1040 (memq calc-language calc-lang-allow-percentsigns))
1041 (let ((sx (symbol-name x)))
1042 (when (memq calc-language calc-lang-allow-percentsigns)
1043 (require 'calccomp)
1044 (setq sx (math-to-percentsigns sx)))
1045 (if (memq calc-language calc-lang-allow-underscores)
1046 (setq sx (math-string-restore-underscores sx)))
1047 (intern-soft sx))))
1049 (defun math-string-restore-underscores (x)
1050 "Replace pound signs by underscores in the string x."
1051 (if (string-match "\\`\\(.*\\)#\\(.*\\)\\'" x)
1052 (math-string-restore-underscores
1053 (concat (math-match-substring x 1) "_" (math-match-substring x 2)))
1056 ;;;###autoload
1057 (defun math-read-if (cond op)
1058 (let ((then (math-read-expr-level 0)))
1059 (or (equal math-expr-data ":")
1060 (throw 'syntax "Expected ':'"))
1061 (math-read-token)
1062 (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op)))))
1064 (defun math-factor-after ()
1065 (let ((math-exp-pos math-exp-pos)
1066 math-exp-old-pos math-exp-token math-expr-data)
1067 (math-read-token)
1068 (or (memq math-exp-token '(number symbol dollar hash string))
1069 (and (assoc math-expr-data '(("-") ("+") ("!") ("|") ("/")))
1070 (assoc (concat "u" math-expr-data) math-expr-opers))
1071 (eq (nth 2 (assoc math-expr-data math-expr-opers)) -1)
1072 (assoc math-expr-data '(("(") ("[") ("{"))))))
1074 (defun math-read-factor ()
1075 (let ((math-expr-opers (math-expr-ops))
1077 (cond ((eq math-exp-token 'number)
1078 (let ((num (math-read-number math-expr-data)))
1079 (if (not num)
1080 (progn
1081 (setq math-exp-old-pos math-exp-pos)
1082 (throw 'syntax "Bad format")))
1083 (math-read-token)
1084 (if (and math-read-expr-quotes
1085 (consp num))
1086 (list 'quote num)
1087 num)))
1088 ((and calc-user-parse-table
1089 (setq op (calc-check-user-syntax)))
1091 ((or (equal math-expr-data "-")
1092 (equal math-expr-data "+")
1093 (equal math-expr-data "!")
1094 (equal math-expr-data "|")
1095 (equal math-expr-data "/"))
1096 (setq math-expr-data (concat "u" math-expr-data))
1097 (math-read-factor))
1098 ((and (setq op (assoc math-expr-data math-expr-opers))
1099 (eq (nth 2 op) -1))
1100 (if (consp (nth 1 op))
1101 (funcall (car (nth 1 op)) op)
1102 (math-read-token)
1103 (let ((val (math-read-expr-level (nth 3 op))))
1104 (cond ((eq (nth 1 op) 'ident)
1105 val)
1106 ((and (Math-numberp val)
1107 (equal (car op) "u-"))
1108 (math-neg val))
1109 (t (list (nth 1 op) val))))))
1110 ((eq math-exp-token 'symbol)
1111 (let ((sym (intern math-expr-data)))
1112 (math-read-token)
1113 (if (equal math-expr-data calc-function-open)
1114 (let ((f (assq sym math-expr-function-mapping)))
1115 (math-read-token)
1116 (if (consp (cdr f))
1117 (funcall (car (cdr f)) f sym)
1118 (let ((args (if (or (equal math-expr-data calc-function-close)
1119 (eq math-exp-token 'end))
1121 (math-read-expr-list))))
1122 (if (not (or (equal math-expr-data calc-function-close)
1123 (eq math-exp-token 'end)))
1124 (throw 'syntax "Expected `)'"))
1125 (math-read-token)
1126 (if (and (memq calc-language
1127 calc-lang-parens-are-subscripts)
1128 args
1129 (require 'calc-ext)
1130 (let ((calc-matrix-mode 'scalar))
1131 (math-known-matrixp
1132 (list 'var sym
1133 (intern
1134 (concat "var-"
1135 (symbol-name sym)))))))
1136 (math-parse-fortran-subscr sym args)
1137 (if f
1138 (setq sym (cdr f))
1139 (and (= (aref (symbol-name sym) 0) ?\\)
1140 (< (prefix-numeric-value calc-language-option)
1142 (setq sym (intern (substring (symbol-name sym)
1143 1))))
1144 (or (string-match "-" (symbol-name sym))
1145 (setq sym (intern
1146 (concat "calcFunc-"
1147 (symbol-name sym))))))
1148 (cons sym args)))))
1149 (if math-read-expr-quotes
1151 (let ((val (list 'var
1152 (intern (math-remove-dashes
1153 (symbol-name sym)))
1154 (if (string-match "-" (symbol-name sym))
1156 (intern (concat "var-"
1157 (symbol-name sym)))))))
1158 (let ((v (or
1159 (assq (nth 1 val) math-expr-variable-mapping)
1160 (assq (math-restore-placeholders (nth 1 val))
1161 math-expr-variable-mapping))))
1162 (and v (setq val (if (consp (cdr v))
1163 (funcall (car (cdr v)) v val)
1164 (list 'var
1165 (intern
1166 (substring (symbol-name (cdr v))
1168 (cdr v))))))
1169 (while (and (memq calc-language
1170 calc-lang-brackets-are-subscripts)
1171 (equal math-expr-data "["))
1172 (math-read-token)
1173 (let ((el (math-read-expr-list)))
1174 (while el
1175 (setq val (append (list 'calcFunc-subscr val)
1176 (list (car el))))
1177 (setq el (cdr el))))
1178 (if (equal math-expr-data "]")
1179 (math-read-token)
1180 (throw 'syntax "Expected ']'")))
1181 val)))))
1182 ((eq math-exp-token 'dollar)
1183 (let ((abs (if (> math-expr-data 0) math-expr-data (- math-expr-data))))
1184 (if (>= (length calc-dollar-values) abs)
1185 (let ((num math-expr-data))
1186 (math-read-token)
1187 (setq calc-dollar-used (max calc-dollar-used num))
1188 (math-check-complete (nth (1- abs) calc-dollar-values)))
1189 (throw 'syntax (if calc-dollar-values
1190 "Too many $'s"
1191 "$'s not allowed in this context")))))
1192 ((eq math-exp-token 'hash)
1193 (or calc-hashes-used
1194 (throw 'syntax "#'s not allowed in this context"))
1195 (require 'calc-ext)
1196 (if (<= math-expr-data (length calc-arg-values))
1197 (let ((num math-expr-data))
1198 (math-read-token)
1199 (setq calc-hashes-used (max calc-hashes-used num))
1200 (nth (1- num) calc-arg-values))
1201 (throw 'syntax "Too many # arguments")))
1202 ((equal math-expr-data "(")
1203 (let* ((exp (let ((math-exp-keep-spaces nil))
1204 (math-read-token)
1205 (if (or (equal math-expr-data "\\dots")
1206 (equal math-expr-data "\\ldots"))
1207 '(neg (var inf var-inf))
1208 (math-read-expr-level 0)))))
1209 (let ((math-exp-keep-spaces nil))
1210 (cond
1211 ((equal math-expr-data ",")
1212 (progn
1213 (math-read-token)
1214 (let ((exp2 (math-read-expr-level 0)))
1215 (setq exp
1216 (if (and exp2 (Math-realp exp) (Math-realp exp2))
1217 (math-normalize (list 'cplx exp exp2))
1218 (list '+ exp (list '* exp2 '(var i var-i))))))))
1219 ((equal math-expr-data ";")
1220 (progn
1221 (math-read-token)
1222 (let ((exp2 (math-read-expr-level 0)))
1223 (setq exp (if (and exp2 (Math-realp exp)
1224 (Math-anglep exp2))
1225 (math-normalize (list 'polar exp exp2))
1226 (require 'calc-ext)
1227 (list '* exp
1228 (list 'calcFunc-exp
1229 (list '*
1230 (math-to-radians-2 exp2)
1231 '(var i var-i)))))))))
1232 ((or (equal math-expr-data "\\dots")
1233 (equal math-expr-data "\\ldots"))
1234 (progn
1235 (math-read-token)
1236 (let ((exp2 (if (or (equal math-expr-data ")")
1237 (equal math-expr-data "]")
1238 (eq math-exp-token 'end))
1239 '(var inf var-inf)
1240 (math-read-expr-level 0))))
1241 (setq exp
1242 (list 'intv
1243 (if (equal math-expr-data ")") 0 1)
1245 exp2)))))))
1246 (if (not (or (equal math-expr-data ")")
1247 (and (equal math-expr-data "]") (eq (car-safe exp) 'intv))
1248 (eq math-exp-token 'end)))
1249 (throw 'syntax "Expected `)'"))
1250 (math-read-token)
1251 exp))
1252 ((eq math-exp-token 'string)
1253 (require 'calc-ext)
1254 (math-read-string))
1255 ((equal math-expr-data "[")
1256 (require 'calc-ext)
1257 (math-read-brackets t "]"))
1258 ((equal math-expr-data "{")
1259 (require 'calc-ext)
1260 (math-read-brackets nil "}"))
1261 ((equal math-expr-data "<")
1262 (require 'calc-ext)
1263 (math-read-angle-brackets))
1264 (t (throw 'syntax "Expected a number")))))
1266 (provide 'calc-aent)
1268 ;; Local variables:
1269 ;; coding: utf-8
1270 ;; generated-autoload-file: "calc-loaddefs.el"
1271 ;; End:
1273 ;;; calc-aent.el ends here