(syms_of_search) <search-spaces-regexp>: Move 'doc:'
[bpt/emacs.git] / lisp / calc / calc-aent.el
CommitLineData
3132f345
CW
1;;; calc-aent.el --- algebraic entry functions for Calc
2
4db56602 3;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
3132f345
CW
4
5;; Author: Dave Gillespie <daveg@synaptics.com>
c4446fc2 6;; Maintainer: Jay Belanger <belanger@truman.edu>
136211a9
EZ
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is distributed in the hope that it will be useful,
11;; but WITHOUT ANY WARRANTY. No author or distributor
12;; accepts responsibility to anyone for the consequences of using it
13;; or for whether it serves any particular purpose or works at all,
14;; unless he says so in writing. Refer to the GNU Emacs General Public
15;; License for full details.
16
17;; Everyone is granted permission to copy, modify and redistribute
18;; GNU Emacs, but only under the conditions described in the
19;; GNU Emacs General Public License. A copy of this license is
20;; supposed to have been given to you along with GNU Emacs so you
21;; can know your rights and responsibilities. It should be in a
22;; file named COPYING. Among other things, the copyright notice
23;; and this notice must be preserved on all copies.
24
3132f345 25;;; Commentary:
136211a9 26
3132f345 27;;; Code:
136211a9
EZ
28
29;; This file is autoloaded from calc.el.
30(require 'calc)
31
32(require 'calc-macs)
f20be8fe 33(eval-when-compile '(require calc-macs))
136211a9
EZ
34
35(defun calc-Need-calc-aent () nil)
36
37
38(defun calc-do-quick-calc ()
39 (calc-check-defines)
40 (if (eq major-mode 'calc-mode)
41 (calc-algebraic-entry t)
42 (let (buf shortbuf)
43 (save-excursion
44 (calc-create-buffer)
45 (let* ((calc-command-flags nil)
46 (calc-dollar-values calc-quick-prev-results)
47 (calc-dollar-used 0)
48 (enable-recursive-minibuffers t)
49 (calc-language (if (memq calc-language '(nil big))
50 'flat calc-language))
51 (entry (calc-do-alg-entry "" "Quick calc: " t))
52 (alg-exp (mapcar (function
53 (lambda (x)
54 (if (and (not calc-extensions-loaded)
55 calc-previous-alg-entry
56 (string-match
57 "\\`[-0-9._+*/^() ]+\\'"
58 calc-previous-alg-entry))
59 (calc-normalize x)
60 (calc-extensions)
61 (math-evaluate-expr x))))
62 entry)))
3132f345
CW
63 (when (and (= (length alg-exp) 1)
64 (eq (car-safe (car alg-exp)) 'calcFunc-assign)
65 (= (length (car alg-exp)) 3)
66 (eq (car-safe (nth 1 (car alg-exp))) 'var))
67 (calc-extensions)
68 (set (nth 2 (nth 1 (car alg-exp))) (nth 2 (car alg-exp)))
69 (calc-refresh-evaltos (nth 2 (nth 1 (car alg-exp))))
70 (setq alg-exp (list (nth 2 (car alg-exp)))))
136211a9
EZ
71 (setq calc-quick-prev-results alg-exp
72 buf (mapconcat (function (lambda (x)
73 (math-format-value x 1000)))
74 alg-exp
75 " ")
76 shortbuf buf)
77 (if (and (= (length alg-exp) 1)
78 (memq (car-safe (car alg-exp)) '(nil bigpos bigneg))
79 (< (length buf) 20)
80 (= calc-number-radix 10))
81 (setq buf (concat buf " ("
82 (let ((calc-number-radix 16))
83 (math-format-value (car alg-exp) 1000))
84 ", "
85 (let ((calc-number-radix 8))
86 (math-format-value (car alg-exp) 1000))
87 (if (and (integerp (car alg-exp))
88 (> (car alg-exp) 0)
89 (< (car alg-exp) 127))
90 (format ", \"%c\"" (car alg-exp))
91 "")
92 ")")))
f20be8fe 93 (if (and (< (length buf) (frame-width)) (= (length entry) 1)
136211a9
EZ
94 calc-extensions-loaded)
95 (let ((long (concat (math-format-value (car entry) 1000)
96 " => " buf)))
f20be8fe 97 (if (<= (length long) (- (frame-width) 8))
136211a9
EZ
98 (setq buf long))))
99 (calc-handle-whys)
100 (message "Result: %s" buf)))
101 (if (eq last-command-char 10)
102 (insert shortbuf)
3cedbf72 103 (kill-new shortbuf)))))
136211a9
EZ
104
105(defun calc-do-calc-eval (str separator args)
106 (calc-check-defines)
107 (catch 'calc-error
108 (save-excursion
109 (calc-create-buffer)
110 (cond
111 ((and (consp str) (not (symbolp (car str))))
112 (let ((calc-language nil)
113 (math-expr-opers math-standard-opers)
114 (calc-internal-prec 12)
115 (calc-word-size 32)
116 (calc-symbolic-mode nil)
117 (calc-matrix-mode nil)
118 (calc-angle-mode 'deg)
119 (calc-number-radix 10)
120 (calc-leading-zeros nil)
121 (calc-group-digits nil)
122 (calc-point-char ".")
123 (calc-frac-format '(":" nil))
124 (calc-prefer-frac nil)
125 (calc-hms-format "%s@ %s' %s\"")
126 (calc-date-format '((H ":" mm C SS pp " ")
127 Www " " Mmm " " D ", " YYYY))
128 (calc-float-format '(float 0))
129 (calc-full-float-format '(float 0))
130 (calc-complex-format nil)
131 (calc-matrix-just nil)
132 (calc-full-vectors t)
133 (calc-break-vectors nil)
134 (calc-vector-commas ",")
135 (calc-vector-brackets "[]")
136 (calc-matrix-brackets '(R O))
137 (calc-complex-mode 'cplx)
138 (calc-infinite-mode nil)
139 (calc-display-strings nil)
140 (calc-simplify-mode nil)
141 (calc-display-working-message 'lots)
142 (strp (cdr str)))
143 (while strp
144 (set (car strp) (nth 1 strp))
145 (setq strp (cdr (cdr strp))))
146 (calc-do-calc-eval (car str) separator args)))
147 ((eq separator 'eval)
148 (eval str))
149 ((eq separator 'macro)
150 (calc-extensions)
151 (let* ((calc-buffer (current-buffer))
152 (calc-window (get-buffer-window calc-buffer))
153 (save-window (selected-window)))
154 (if calc-window
155 (unwind-protect
156 (progn
157 (select-window calc-window)
158 (calc-execute-kbd-macro str nil (car args)))
159 (and (window-point save-window)
160 (select-window save-window)))
161 (save-window-excursion
162 (select-window (get-largest-window))
163 (switch-to-buffer calc-buffer)
164 (calc-execute-kbd-macro str nil (car args)))))
165 nil)
166 ((eq separator 'pop)
167 (or (not (integerp str))
168 (= str 0)
169 (calc-pop (min str (calc-stack-size))))
170 (calc-stack-size))
171 ((eq separator 'top)
172 (and (integerp str)
173 (> str 0)
174 (<= str (calc-stack-size))
175 (math-format-value (calc-top-n str (car args)) 1000)))
176 ((eq separator 'rawtop)
177 (and (integerp str)
178 (> str 0)
179 (<= str (calc-stack-size))
180 (calc-top-n str (car args))))
181 (t
182 (let* ((calc-command-flags nil)
183 (calc-next-why nil)
184 (calc-language (if (memq calc-language '(nil big))
185 'flat calc-language))
186 (calc-dollar-values (mapcar
187 (function
188 (lambda (x)
189 (if (stringp x)
190 (progn
191 (setq x (math-read-exprs x))
192 (if (eq (car-safe x)
193 'error)
194 (throw 'calc-error
195 (calc-eval-error
196 (cdr x)))
197 (car x)))
198 x)))
199 args))
200 (calc-dollar-used 0)
201 (res (if (stringp str)
202 (math-read-exprs str)
203 (list str)))
204 buf)
205 (if (eq (car res) 'error)
206 (calc-eval-error (cdr res))
207 (setq res (mapcar 'calc-normalize res))
208 (and (memq 'clear-message calc-command-flags)
209 (message ""))
210 (cond ((eq separator 'pred)
211 (calc-extensions)
212 (if (= (length res) 1)
213 (math-is-true (car res))
214 (calc-eval-error '(0 "Single value expected"))))
215 ((eq separator 'raw)
216 (if (= (length res) 1)
217 (car res)
218 (calc-eval-error '(0 "Single value expected"))))
219 ((eq separator 'list)
220 res)
221 ((memq separator '(num rawnum))
222 (if (= (length res) 1)
223 (if (math-constp (car res))
224 (if (eq separator 'num)
225 (math-format-value (car res) 1000)
226 (car res))
227 (calc-eval-error
228 (list 0
229 (if calc-next-why
230 (calc-explain-why (car calc-next-why))
231 "Number expected"))))
232 (calc-eval-error '(0 "Single value expected"))))
233 ((eq separator 'push)
234 (calc-push-list res)
235 nil)
236 (t (while res
237 (setq buf (concat buf
238 (and buf (or separator ", "))
239 (math-format-value (car res) 1000))
240 res (cdr res)))
07ff2bc8 241 buf)))))))))
136211a9
EZ
242
243(defun calc-eval-error (msg)
244 (if (and (boundp 'calc-eval-error)
245 calc-eval-error)
246 (if (eq calc-eval-error 'string)
247 (nth 1 msg)
248 (error "%s" (nth 1 msg)))
07ff2bc8 249 msg))
136211a9
EZ
250
251
252;;;; Reading an expression in algebraic form.
253
254(defun calc-auto-algebraic-entry (&optional prefix)
255 (interactive "P")
07ff2bc8 256 (calc-algebraic-entry prefix t))
136211a9
EZ
257
258(defun calc-algebraic-entry (&optional prefix auto)
259 (interactive "P")
260 (calc-wrapper
261 (let ((calc-language (if prefix nil calc-language))
262 (math-expr-opers (if prefix math-standard-opers math-expr-opers)))
07ff2bc8 263 (calc-alg-entry (and auto (char-to-string last-command-char))))))
136211a9
EZ
264
265(defun calc-alg-entry (&optional initial prompt)
266 (let* ((sel-mode nil)
267 (calc-dollar-values (mapcar 'calc-get-stack-element
268 (nthcdr calc-stack-top calc-stack)))
269 (calc-dollar-used 0)
270 (calc-plain-entry t)
271 (alg-exp (calc-do-alg-entry initial prompt t)))
272 (if (stringp alg-exp)
273 (progn
274 (calc-extensions)
275 (calc-alg-edit alg-exp))
276 (let* ((calc-simplify-mode (if (eq last-command-char ?\C-j)
277 'none
278 calc-simplify-mode))
279 (nvals (mapcar 'calc-normalize alg-exp)))
280 (while alg-exp
281 (calc-record (if calc-extensions-loaded (car alg-exp) (car nvals))
282 "alg'")
283 (calc-pop-push-record-list calc-dollar-used
284 (and (not (equal (car alg-exp)
285 (car nvals)))
286 calc-extensions-loaded
287 "")
288 (list (car nvals)))
289 (setq alg-exp (cdr alg-exp)
290 nvals (cdr nvals)
291 calc-dollar-used 0)))
07ff2bc8 292 (calc-handle-whys))))
136211a9 293
1480882c
JB
294(defvar calc-alg-ent-map nil
295 "The keymap used for algebraic entry.")
296
297(defvar calc-alg-ent-esc-map nil
298 "The keymap used for escapes in algebraic entry.")
299
3cedbf72
JB
300(defvar calc-alg-exp)
301
136211a9
EZ
302(defun calc-do-alg-entry (&optional initial prompt no-normalize)
303 (let* ((calc-buffer (current-buffer))
4db56602 304 (blink-paren-function 'calcAlg-blink-matching-open)
3cedbf72 305 (calc-alg-exp 'error))
1480882c 306 (unless calc-alg-ent-map
136211a9
EZ
307 (setq calc-alg-ent-map (copy-keymap minibuffer-local-map))
308 (define-key calc-alg-ent-map "'" 'calcAlg-previous)
309 (define-key calc-alg-ent-map "`" 'calcAlg-edit)
310 (define-key calc-alg-ent-map "\C-m" 'calcAlg-enter)
311 (define-key calc-alg-ent-map "\C-j" 'calcAlg-enter)
f1625eaa
JB
312 (let ((i 33))
313 (setq calc-alg-ent-esc-map (copy-keymap esc-map))
314 (while (< i 127)
315 (aset (nth 1 calc-alg-ent-esc-map) i 'calcAlg-escape)
316 (setq i (1+ i)))))
317 (define-key calc-alg-ent-map "\e" nil)
136211a9
EZ
318 (if (eq calc-algebraic-mode 'total)
319 (define-key calc-alg-ent-map "\e" calc-alg-ent-esc-map)
320 (define-key calc-alg-ent-map "\ep" 'calcAlg-plus-minus)
321 (define-key calc-alg-ent-map "\em" 'calcAlg-mod)
322 (define-key calc-alg-ent-map "\e=" 'calcAlg-equals)
323 (define-key calc-alg-ent-map "\e\r" 'calcAlg-equals)
324 (define-key calc-alg-ent-map "\e%" 'self-insert-command))
325 (setq calc-aborted-prefix nil)
326 (let ((buf (read-from-minibuffer (or prompt "Algebraic: ")
327 (or initial "")
328 calc-alg-ent-map nil)))
3cedbf72
JB
329 (when (eq calc-alg-exp 'error)
330 (when (eq (car-safe (setq calc-alg-exp (math-read-exprs buf))) 'error)
331 (setq calc-alg-exp nil)))
136211a9
EZ
332 (setq calc-aborted-prefix "alg'")
333 (or no-normalize
3cedbf72
JB
334 (and calc-alg-exp (setq calc-alg-exp (mapcar 'calc-normalize calc-alg-exp))))
335 calc-alg-exp)))
136211a9
EZ
336
337(defun calcAlg-plus-minus ()
338 (interactive)
339 (if (calc-minibuffer-contains ".* \\'")
340 (insert "+/- ")
07ff2bc8 341 (insert " +/- ")))
136211a9
EZ
342
343(defun calcAlg-mod ()
344 (interactive)
345 (if (not (calc-minibuffer-contains ".* \\'"))
346 (insert " "))
347 (if (calc-minibuffer-contains ".* mod +\\'")
348 (if calc-previous-modulo
349 (insert (math-format-flat-expr calc-previous-modulo 0))
350 (beep))
07ff2bc8 351 (insert "mod ")))
136211a9
EZ
352
353(defun calcAlg-previous ()
354 (interactive)
aa9208fb 355 (if (calc-minibuffer-contains "\\'")
136211a9
EZ
356 (if calc-previous-alg-entry
357 (insert calc-previous-alg-entry)
358 (beep))
07ff2bc8 359 (insert "'")))
136211a9
EZ
360
361(defun calcAlg-equals ()
362 (interactive)
363 (unwind-protect
364 (calcAlg-enter)
3cedbf72
JB
365 (if (consp calc-alg-exp)
366 (progn (setq prefix-arg (length calc-alg-exp))
07ff2bc8 367 (calc-unread-command ?=)))))
136211a9
EZ
368
369(defun calcAlg-escape ()
370 (interactive)
371 (calc-unread-command)
372 (save-excursion
373 (calc-select-buffer)
374 (use-local-map calc-mode-map))
07ff2bc8 375 (calcAlg-enter))
136211a9 376
3132f345 377(defvar calc-plain-entry nil)
136211a9
EZ
378(defun calcAlg-edit ()
379 (interactive)
380 (if (or (not calc-plain-entry)
381 (calc-minibuffer-contains
382 "\\`\\([^\"]*\"[^\"]*\"\\)*[^\"]*\"[^\"]*\\'"))
383 (insert "`")
3cedbf72
JB
384 (setq calc-alg-exp (minibuffer-contents))
385 (and (> (length calc-alg-exp) 0) (setq calc-previous-alg-entry calc-alg-exp))
07ff2bc8 386 (exit-minibuffer)))
136211a9
EZ
387
388(defun calcAlg-enter ()
389 (interactive)
f20be8fe 390 (let* ((str (minibuffer-contents))
136211a9
EZ
391 (exp (and (> (length str) 0)
392 (save-excursion
393 (set-buffer calc-buffer)
394 (math-read-exprs str)))))
395 (if (eq (car-safe exp) 'error)
396 (progn
f20be8fe 397 (goto-char (minibuffer-prompt-end))
136211a9
EZ
398 (forward-char (nth 1 exp))
399 (beep)
400 (calc-temp-minibuffer-message
401 (concat " [" (or (nth 2 exp) "Error") "]"))
402 (calc-clear-unread-commands))
3cedbf72 403 (setq calc-alg-exp (if (calc-minibuffer-contains "\\` *\\[ *\\'")
136211a9
EZ
404 '((incomplete vec))
405 exp))
406 (and (> (length str) 0) (setq calc-previous-alg-entry str))
07ff2bc8 407 (exit-minibuffer))))
136211a9
EZ
408
409(defun calcAlg-blink-matching-open ()
410 (let ((oldpos (point))
411 (blinkpos nil))
412 (save-excursion
413 (condition-case ()
414 (setq blinkpos (scan-sexps oldpos -1))
415 (error nil)))
416 (if (and blinkpos
417 (> oldpos (1+ (point-min)))
418 (or (and (= (char-after (1- oldpos)) ?\))
419 (= (char-after blinkpos) ?\[))
420 (and (= (char-after (1- oldpos)) ?\])
421 (= (char-after blinkpos) ?\()))
422 (save-excursion
423 (goto-char blinkpos)
424 (looking-at ".+\\(\\.\\.\\|\\\\dots\\|\\\\ldots\\)")))
425 (let ((saved (aref (syntax-table) (char-after blinkpos))))
426 (unwind-protect
427 (progn
428 (aset (syntax-table) (char-after blinkpos)
429 (+ (logand saved 255)
430 (lsh (char-after (1- oldpos)) 8)))
431 (blink-matching-open))
432 (aset (syntax-table) (char-after blinkpos) saved)))
07ff2bc8 433 (blink-matching-open))))
136211a9
EZ
434
435
436(defun calc-alg-digit-entry ()
a1506d29 437 (calc-alg-entry
136211a9
EZ
438 (cond ((eq last-command-char ?e)
439 (if (> calc-number-radix 14) (format "%d.^" calc-number-radix) "1e"))
440 ((eq last-command-char ?#) (format "%d#" calc-number-radix))
441 ((eq last-command-char ?_) "-")
442 ((eq last-command-char ?@) "0@ ")
07ff2bc8 443 (t (char-to-string last-command-char)))))
136211a9
EZ
444
445(defun calcDigit-algebraic ()
446 (interactive)
447 (if (calc-minibuffer-contains ".*[@oh] *[^'m ]+[^'m]*\\'")
448 (calcDigit-key)
f20be8fe 449 (setq calc-digit-value (minibuffer-contents))
07ff2bc8 450 (exit-minibuffer)))
136211a9
EZ
451
452(defun calcDigit-edit ()
453 (interactive)
454 (calc-unread-command)
f20be8fe 455 (setq calc-digit-value (minibuffer-contents))
07ff2bc8 456 (exit-minibuffer))
136211a9
EZ
457
458
459;;; Algebraic expression parsing. [Public]
460
3cedbf72
JB
461;;; The next few variables are local to math-read-exprs (and math-read-expr)
462;;; but are set in functions they call.
463
464(defvar math-exp-pos)
465(defvar math-exp-str)
466(defvar math-exp-old-pos)
467(defvar math-exp-token)
468(defvar math-exp-keep-spaces)
469
470(defun math-read-exprs (math-exp-str)
471 (let ((math-exp-pos 0)
472 (math-exp-old-pos 0)
473 (math-exp-keep-spaces nil)
474 math-exp-token math-expr-data)
c4446fc2 475 (setq math-exp-str (math-read-preprocess-string math-exp-str))
136211a9 476 (if calc-language-input-filter
3cedbf72
JB
477 (setq math-exp-str (funcall calc-language-input-filter math-exp-str)))
478 (while (setq math-exp-token (string-match "\\.\\.\\([^.]\\|.[^.]\\)" math-exp-str))
479 (setq math-exp-str (concat (substring math-exp-str 0 math-exp-token) "\\dots"
480 (substring math-exp-str (+ math-exp-token 2)))))
136211a9
EZ
481 (math-build-parse-table)
482 (math-read-token)
483 (let ((val (catch 'syntax (math-read-expr-list))))
484 (if (stringp val)
3cedbf72
JB
485 (list 'error math-exp-old-pos val)
486 (if (equal math-exp-token 'end)
136211a9 487 val
3cedbf72 488 (list 'error math-exp-old-pos "Syntax error"))))))
136211a9
EZ
489
490(defun math-read-expr-list ()
3cedbf72 491 (let* ((math-exp-keep-spaces nil)
136211a9
EZ
492 (val (list (math-read-expr-level 0)))
493 (last val))
abd880c3 494 (while (equal math-expr-data ",")
136211a9
EZ
495 (math-read-token)
496 (let ((rest (list (math-read-expr-level 0))))
497 (setcdr last rest)
498 (setq last rest)))
07ff2bc8 499 val))
136211a9 500
3132f345
CW
501(defvar calc-user-parse-table nil)
502(defvar calc-last-main-parse-table nil)
503(defvar calc-last-lang-parse-table nil)
504(defvar calc-user-tokens nil)
505(defvar calc-user-token-chars nil)
136211a9 506
3cedbf72
JB
507(defvar math-toks nil
508 "Tokens to pass between math-build-parse-table and math-find-user-tokens.")
509
136211a9
EZ
510(defun math-build-parse-table ()
511 (let ((mtab (cdr (assq nil calc-user-parse-tables)))
512 (ltab (cdr (assq calc-language calc-user-parse-tables))))
513 (or (and (eq mtab calc-last-main-parse-table)
514 (eq ltab calc-last-lang-parse-table))
515 (let ((p (append mtab ltab))
3cedbf72 516 (math-toks nil))
136211a9
EZ
517 (setq calc-user-parse-table p)
518 (setq calc-user-token-chars nil)
519 (while p
520 (math-find-user-tokens (car (car p)))
521 (setq p (cdr p)))
522 (setq calc-user-tokens (mapconcat 'identity
3cedbf72 523 (sort (mapcar 'car math-toks)
136211a9
EZ
524 (function (lambda (x y)
525 (> (length x)
526 (length y)))))
527 "\\|")
528 calc-last-main-parse-table mtab
07ff2bc8 529 calc-last-lang-parse-table ltab)))))
136211a9 530
3cedbf72 531(defun math-find-user-tokens (p)
136211a9
EZ
532 (while p
533 (cond ((and (stringp (car p))
534 (or (> (length (car p)) 1) (equal (car p) "$")
535 (equal (car p) "\""))
536 (string-match "[^a-zA-Z0-9]" (car p)))
537 (let ((s (regexp-quote (car p))))
538 (if (string-match "\\`[a-zA-Z0-9]" s)
539 (setq s (concat "\\<" s)))
540 (if (string-match "[a-zA-Z0-9]\\'" s)
541 (setq s (concat s "\\>")))
3cedbf72 542 (or (assoc s math-toks)
136211a9 543 (progn
3cedbf72 544 (setq math-toks (cons (list s) math-toks))
136211a9
EZ
545 (or (memq (aref (car p) 0) calc-user-token-chars)
546 (setq calc-user-token-chars
547 (cons (aref (car p) 0)
548 calc-user-token-chars)))))))
549 ((consp (car p))
550 (math-find-user-tokens (nth 1 (car p)))
551 (or (eq (car (car p)) '\?)
552 (math-find-user-tokens (nth 2 (car p))))))
07ff2bc8 553 (setq p (cdr p))))
136211a9
EZ
554
555(defun math-read-token ()
3cedbf72
JB
556 (if (>= math-exp-pos (length math-exp-str))
557 (setq math-exp-old-pos math-exp-pos
558 math-exp-token 'end
abd880c3 559 math-expr-data "\000")
3cedbf72
JB
560 (let ((ch (aref math-exp-str math-exp-pos)))
561 (setq math-exp-old-pos math-exp-pos)
136211a9 562 (cond ((memq ch '(32 10 9))
3cedbf72
JB
563 (setq math-exp-pos (1+ math-exp-pos))
564 (if math-exp-keep-spaces
565 (setq math-exp-token 'space
abd880c3 566 math-expr-data " ")
136211a9
EZ
567 (math-read-token)))
568 ((and (memq ch calc-user-token-chars)
569 (let ((case-fold-search nil))
3cedbf72
JB
570 (eq (string-match calc-user-tokens math-exp-str math-exp-pos)
571 math-exp-pos)))
572 (setq math-exp-token 'punc
573 math-expr-data (math-match-substring math-exp-str 0)
574 math-exp-pos (match-end 0)))
136211a9
EZ
575 ((or (and (>= ch ?a) (<= ch ?z))
576 (and (>= ch ?A) (<= ch ?Z)))
577 (string-match (if (memq calc-language '(c fortran pascal maple))
578 "[a-zA-Z0-9_#]*"
579 "[a-zA-Z0-9'#]*")
3cedbf72
JB
580 math-exp-str math-exp-pos)
581 (setq math-exp-token 'symbol
582 math-exp-pos (match-end 0)
abd880c3 583 math-expr-data (math-restore-dashes
3cedbf72 584 (math-match-substring math-exp-str 0)))
136211a9 585 (if (eq calc-language 'eqn)
abd880c3 586 (let ((code (assoc math-expr-data math-eqn-ignore-words)))
136211a9
EZ
587 (cond ((null code))
588 ((null (cdr code))
589 (math-read-token))
590 ((consp (nth 1 code))
591 (math-read-token)
abd880c3
JB
592 (if (assoc math-expr-data (cdr code))
593 (setq math-expr-data (format "%s %s"
594 (car code) math-expr-data))))
136211a9 595 ((eq (nth 1 code) 'punc)
3cedbf72 596 (setq math-exp-token 'punc
abd880c3 597 math-expr-data (nth 2 code)))
136211a9
EZ
598 (t
599 (math-read-token)
600 (math-read-token))))))
601 ((or (and (>= ch ?0) (<= ch ?9))
602 (and (eq ch '?\.)
3cedbf72
JB
603 (eq (string-match "\\.[0-9]" math-exp-str math-exp-pos)
604 math-exp-pos))
136211a9 605 (and (eq ch '?_)
3cedbf72
JB
606 (eq (string-match "_\\.?[0-9]" math-exp-str math-exp-pos)
607 math-exp-pos)
608 (or (eq math-exp-pos 0)
136211a9
EZ
609 (and (memq calc-language '(nil flat big unform
610 tex eqn))
611 (eq (string-match "[^])}\"a-zA-Z0-9'$]_"
3cedbf72
JB
612 math-exp-str (1- math-exp-pos))
613 (1- math-exp-pos))))))
136211a9 614 (or (and (eq calc-language 'c)
3cedbf72
JB
615 (string-match "0[xX][0-9a-fA-F]+" math-exp-str math-exp-pos))
616 (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]+\\)?\"?\\)?"
617 math-exp-str math-exp-pos))
618 (setq math-exp-token 'number
619 math-expr-data (math-match-substring math-exp-str 0)
620 math-exp-pos (match-end 0)))
136211a9
EZ
621 ((eq ch ?\$)
622 (if (and (eq calc-language 'pascal)
623 (eq (string-match
624 "\\(\\$[0-9a-fA-F]+\\)\\($\\|[^0-9a-zA-Z]\\)"
3cedbf72
JB
625 math-exp-str math-exp-pos)
626 math-exp-pos))
627 (setq math-exp-token 'number
628 math-expr-data (math-match-substring math-exp-str 1)
629 math-exp-pos (match-end 1))
630 (if (eq (string-match "\\$\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
631 math-exp-pos)
abd880c3 632 (setq math-expr-data (- (string-to-int (math-match-substring
3cedbf72
JB
633 math-exp-str 1))))
634 (string-match "\\$+" math-exp-str math-exp-pos)
abd880c3 635 (setq math-expr-data (- (match-end 0) (match-beginning 0))))
3cedbf72
JB
636 (setq math-exp-token 'dollar
637 math-exp-pos (match-end 0))))
136211a9 638 ((eq ch ?\#)
3cedbf72
JB
639 (if (eq (string-match "#\\([1-9][0-9]*\\)" math-exp-str math-exp-pos)
640 math-exp-pos)
abd880c3 641 (setq math-expr-data (string-to-int
3cedbf72
JB
642 (math-match-substring math-exp-str 1))
643 math-exp-pos (match-end 0))
abd880c3 644 (setq math-expr-data 1
3cedbf72
JB
645 math-exp-pos (1+ math-exp-pos)))
646 (setq math-exp-token 'hash))
136211a9 647 ((eq (string-match "~=\\|<=\\|>=\\|<>\\|/=\\|\\+/-\\|\\\\dots\\|\\\\ldots\\|\\*\\*\\|<<\\|>>\\|==\\|!=\\|&&&\\||||\\|!!!\\|&&\\|||\\|!!\\|:=\\|::\\|=>"
3cedbf72
JB
648 math-exp-str math-exp-pos)
649 math-exp-pos)
650 (setq math-exp-token 'punc
651 math-expr-data (math-match-substring math-exp-str 0)
652 math-exp-pos (match-end 0)))
136211a9 653 ((and (eq ch ?\")
3cedbf72
JB
654 (string-match "\\(\"\\([^\"\\]\\|\\\\.\\)*\\)\\(\"\\|\\'\\)"
655 math-exp-str math-exp-pos))
136211a9
EZ
656 (if (eq calc-language 'eqn)
657 (progn
3cedbf72
JB
658 (setq math-exp-str (copy-sequence math-exp-str))
659 (aset math-exp-str (match-beginning 1) ?\{)
660 (if (< (match-end 1) (length math-exp-str))
661 (aset math-exp-str (match-end 1) ?\}))
136211a9 662 (math-read-token))
3cedbf72
JB
663 (setq math-exp-token 'string
664 math-expr-data (math-match-substring math-exp-str 1)
665 math-exp-pos (match-end 0))))
136211a9 666 ((and (= ch ?\\) (eq calc-language 'tex)
3cedbf72
JB
667 (< math-exp-pos (1- (length math-exp-str))))
668 (or (string-match "\\\\hbox *{\\([a-zA-Z0-9]+\\)}"
669 math-exp-str math-exp-pos)
670 (string-match "\\(\\\\\\([a-zA-Z]+\\|[^a-zA-Z]\\)\\)"
671 math-exp-str math-exp-pos))
672 (setq math-exp-token 'symbol
673 math-exp-pos (match-end 0)
abd880c3 674 math-expr-data (math-restore-dashes
3cedbf72 675 (math-match-substring math-exp-str 1)))
abd880c3 676 (let ((code (assoc math-expr-data math-tex-ignore-words)))
136211a9
EZ
677 (cond ((null code))
678 ((null (cdr code))
679 (math-read-token))
680 ((eq (nth 1 code) 'punc)
3cedbf72 681 (setq math-exp-token 'punc
abd880c3 682 math-expr-data (nth 2 code)))
136211a9 683 ((and (eq (nth 1 code) 'mat)
3cedbf72
JB
684 (string-match " *{" math-exp-str math-exp-pos))
685 (setq math-exp-pos (match-end 0)
686 math-exp-token 'punc
abd880c3 687 math-expr-data "[")
3cedbf72 688 (let ((right (string-match "}" math-exp-str math-exp-pos)))
136211a9 689 (and right
3cedbf72
JB
690 (setq math-exp-str (copy-sequence math-exp-str))
691 (aset math-exp-str right ?\])))))))
136211a9
EZ
692 ((and (= ch ?\.) (eq calc-language 'fortran)
693 (eq (string-match "\\.[a-zA-Z][a-zA-Z][a-zA-Z]?\\."
3cedbf72
JB
694 math-exp-str math-exp-pos) math-exp-pos))
695 (setq math-exp-token 'punc
696 math-expr-data (upcase (math-match-substring math-exp-str 0))
697 math-exp-pos (match-end 0)))
136211a9 698 ((and (eq calc-language 'math)
3cedbf72
JB
699 (eq (string-match "\\[\\[\\|->\\|:>" 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)))
136211a9
EZ
704 ((and (eq calc-language 'eqn)
705 (eq (string-match "->\\|<-\\|+-\\|\\\\dots\\|~\\|\\^"
3cedbf72
JB
706 math-exp-str math-exp-pos)
707 math-exp-pos))
708 (setq math-exp-token 'punc
709 math-expr-data (math-match-substring math-exp-str 0)
710 math-exp-pos (match-end 0))
711 (and (eq (string-match "\\\\dots\\." math-exp-str math-exp-pos)
712 math-exp-pos)
713 (setq math-exp-pos (match-end 0)))
abd880c3 714 (if (memq (aref math-expr-data 0) '(?~ ?^))
136211a9 715 (math-read-token)))
3cedbf72
JB
716 ((eq (string-match "%%.*$" math-exp-str math-exp-pos) math-exp-pos)
717 (setq math-exp-pos (match-end 0))
136211a9
EZ
718 (math-read-token))
719 (t
720 (if (and (eq ch ?\{) (memq calc-language '(tex eqn)))
721 (setq ch ?\())
722 (if (and (eq ch ?\}) (memq calc-language '(tex eqn)))
723 (setq ch ?\)))
724 (if (and (eq ch ?\&) (eq calc-language 'tex))
725 (setq ch ?\,))
3cedbf72 726 (setq math-exp-token 'punc
abd880c3 727 math-expr-data (char-to-string ch)
3cedbf72 728 math-exp-pos (1+ math-exp-pos)))))))
136211a9
EZ
729
730
731(defun math-read-expr-level (exp-prec &optional exp-term)
732 (let* ((x (math-read-factor)) (first t) op op2)
733 (while (and (or (and calc-user-parse-table
734 (setq op (calc-check-user-syntax x exp-prec))
735 (setq x op
736 op '("2x" ident 999999 -1)))
abd880c3 737 (and (setq op (assoc math-expr-data math-expr-opers))
136211a9
EZ
738 (/= (nth 2 op) -1)
739 (or (and (setq op2 (assoc
abd880c3 740 math-expr-data
136211a9
EZ
741 (cdr (memq op math-expr-opers))))
742 (eq (= (nth 3 op) -1)
743 (/= (nth 3 op2) -1))
744 (eq (= (nth 3 op2) -1)
745 (not (math-factor-after)))
746 (setq op op2))
747 t))
748 (and (or (eq (nth 2 op) -1)
3cedbf72 749 (memq math-exp-token '(symbol number dollar hash))
abd880c3
JB
750 (equal math-expr-data "(")
751 (and (equal math-expr-data "[")
136211a9 752 (not (eq calc-language 'math))
3cedbf72 753 (not (and math-exp-keep-spaces
136211a9 754 (eq (car-safe x) 'vec)))))
abd880c3 755 (or (not (setq op (assoc math-expr-data math-expr-opers)))
136211a9
EZ
756 (/= (nth 2 op) -1))
757 (or (not calc-user-parse-table)
3cedbf72 758 (not (eq math-exp-token 'symbol))
136211a9
EZ
759 (let ((p calc-user-parse-table))
760 (while (and p
761 (or (not (integerp
762 (car (car (car p)))))
763 (not (equal
764 (nth 1 (car (car p)))
abd880c3 765 math-expr-data))))
136211a9
EZ
766 (setq p (cdr p)))
767 (not p)))
768 (setq op (assoc "2x" math-expr-opers))))
abd880c3 769 (not (and exp-term (equal math-expr-data exp-term)))
136211a9
EZ
770 (>= (nth 2 op) exp-prec))
771 (if (not (equal (car op) "2x"))
772 (math-read-token))
773 (and (memq (nth 1 op) '(sdev mod))
774 (calc-extensions))
775 (setq x (cond ((consp (nth 1 op))
776 (funcall (car (nth 1 op)) x op))
777 ((eq (nth 3 op) -1)
778 (if (eq (nth 1 op) 'ident)
779 x
780 (if (eq (nth 1 op) 'closing)
781 (if (eq (nth 2 op) exp-prec)
782 (progn
783 (setq exp-prec 1000)
784 x)
785 (throw 'syntax "Mismatched delimiters"))
786 (list (nth 1 op) x))))
787 ((and (not first)
788 (memq (nth 1 op) math-alg-inequalities)
789 (memq (car-safe x) math-alg-inequalities))
790 (calc-extensions)
791 (math-composite-inequalities x op))
792 (t (list (nth 1 op)
793 x
794 (math-read-expr-level (nth 3 op) exp-term))))
795 first nil))
07ff2bc8 796 x))
136211a9
EZ
797
798(defun calc-check-user-syntax (&optional x prec)
799 (let ((p calc-user-parse-table)
800 (matches nil)
801 match rule)
802 (while (and p
803 (or (not (progn
804 (setq rule (car (car p)))
805 (if x
806 (and (integerp (car rule))
807 (>= (car rule) prec)
abd880c3 808 (equal math-expr-data
136211a9 809 (car (setq rule (cdr rule)))))
abd880c3 810 (equal math-expr-data (car rule)))))
3cedbf72
JB
811 (let ((save-exp-pos math-exp-pos)
812 (save-exp-old-pos math-exp-old-pos)
813 (save-exp-token math-exp-token)
abd880c3 814 (save-exp-data math-expr-data))
136211a9
EZ
815 (or (not (listp
816 (setq matches (calc-match-user-syntax rule))))
817 (let ((args (progn
818 (calc-extensions)
819 calc-arg-values))
820 (conds nil)
821 temp)
822 (if x
823 (setq matches (cons x matches)))
824 (setq match (cdr (car p)))
825 (while (and (eq (car-safe match)
826 'calcFunc-condition)
827 (= (length match) 3))
828 (setq conds (append (math-flatten-lands
829 (nth 2 match))
830 conds)
831 match (nth 1 match)))
832 (while (and conds match)
833 (calc-extensions)
834 (cond ((eq (car-safe (car conds))
835 'calcFunc-let)
836 (setq temp (car conds))
837 (or (= (length temp) 3)
838 (and (= (length temp) 2)
839 (eq (car-safe (nth 1 temp))
840 'calcFunc-assign)
841 (= (length (nth 1 temp)) 3)
842 (setq temp (nth 1 temp)))
843 (setq match nil))
844 (setq matches (cons
845 (math-normalize
846 (math-multi-subst
847 (nth 2 temp)
848 args matches))
849 matches)
850 args (cons (nth 1 temp)
851 args)))
852 ((and (eq (car-safe (car conds))
853 'calcFunc-matches)
854 (= (length (car conds)) 3))
855 (setq temp (calcFunc-vmatches
856 (math-multi-subst
857 (nth 1 (car conds))
858 args matches)
859 (nth 2 (car conds))))
860 (if (eq temp 0)
861 (setq match nil)
862 (while (setq temp (cdr temp))
863 (setq matches (cons (nth 2 (car temp))
864 matches)
865 args (cons (nth 1 (car temp))
866 args)))))
867 (t
868 (or (math-is-true (math-simplify
869 (math-multi-subst
870 (car conds)
871 args matches)))
872 (setq match nil))))
873 (setq conds (cdr conds)))
874 (if match
875 (not (setq match (math-multi-subst
876 match args matches)))
3cedbf72
JB
877 (setq math-exp-old-pos save-exp-old-pos
878 math-exp-token save-exp-token
abd880c3 879 math-expr-data save-exp-data
3cedbf72 880 math-exp-pos save-exp-pos)))))))
136211a9 881 (setq p (cdr p)))
07ff2bc8 882 (and p match)))
136211a9
EZ
883
884(defun calc-match-user-syntax (p &optional term)
885 (let ((matches nil)
3cedbf72
JB
886 (save-exp-pos math-exp-pos)
887 (save-exp-old-pos math-exp-old-pos)
888 (save-exp-token math-exp-token)
889 (save-exp-data math-expr-data)
890 m)
136211a9
EZ
891 (while (and p
892 (cond ((stringp (car p))
abd880c3 893 (and (equal math-expr-data (car p))
136211a9
EZ
894 (progn
895 (math-read-token)
896 t)))
897 ((integerp (car p))
898 (and (setq m (catch 'syntax
899 (math-read-expr-level
900 (car p)
901 (if (cdr p)
902 (if (consp (nth 1 p))
903 (car (nth 1 (nth 1 p)))
904 (nth 1 p))
905 term))))
906 (not (stringp m))
907 (setq matches (nconc matches (list m)))))
908 ((eq (car (car p)) '\?)
909 (setq m (calc-match-user-syntax (nth 1 (car p))))
910 (or (nth 2 (car p))
911 (setq matches
912 (nconc matches
913 (list
914 (cons 'vec (and (listp m) m))))))
915 (or (listp m) (not (nth 2 (car p)))
916 (not (eq (aref (car (nth 2 (car p))) 0) ?\$))
3cedbf72 917 (eq math-exp-token 'end)))
136211a9
EZ
918 (t
919 (setq m (calc-match-user-syntax (nth 1 (car p))
920 (car (nth 2 (car p)))))
921 (if (listp m)
922 (let ((vec (cons 'vec m))
923 opos mm)
924 (while (and (listp
3cedbf72 925 (setq opos math-exp-pos
136211a9
EZ
926 mm (calc-match-user-syntax
927 (or (nth 2 (car p))
928 (nth 1 (car p)))
929 (car (nth 2 (car p))))))
3cedbf72 930 (> math-exp-pos opos))
136211a9
EZ
931 (setq vec (nconc vec mm)))
932 (setq matches (nconc matches (list vec))))
933 (and (eq (car (car p)) '*)
934 (setq matches (nconc matches (list '(vec)))))))))
935 (setq p (cdr p)))
936 (if p
3cedbf72
JB
937 (setq math-exp-pos save-exp-pos
938 math-exp-old-pos save-exp-old-pos
939 math-exp-token save-exp-token
abd880c3 940 math-expr-data save-exp-data
136211a9 941 matches "Failed"))
07ff2bc8 942 matches))
136211a9
EZ
943
944(defconst math-alg-inequalities
945 '(calcFunc-lt calcFunc-gt calcFunc-leq calcFunc-geq
946 calcFunc-eq calcFunc-neq))
947
948(defun math-remove-dashes (x)
949 (if (string-match "\\`\\(.*\\)-\\(.*\\)\\'" x)
950 (math-remove-dashes
951 (concat (math-match-substring x 1) "#" (math-match-substring x 2)))
07ff2bc8 952 x))
136211a9
EZ
953
954(defun math-restore-dashes (x)
955 (if (string-match "\\`\\(.*\\)[#_]\\(.*\\)\\'" x)
956 (math-restore-dashes
957 (concat (math-match-substring x 1) "-" (math-match-substring x 2)))
07ff2bc8 958 x))
136211a9
EZ
959
960(defun math-read-if (cond op)
961 (let ((then (math-read-expr-level 0)))
abd880c3 962 (or (equal math-expr-data ":")
136211a9
EZ
963 (throw 'syntax "Expected ':'"))
964 (math-read-token)
07ff2bc8 965 (list 'calcFunc-if cond then (math-read-expr-level (nth 3 op)))))
136211a9
EZ
966
967(defun math-factor-after ()
3cedbf72
JB
968 (let ((math-exp-pos math-exp-pos)
969 math-exp-old-pos math-exp-token math-expr-data)
136211a9 970 (math-read-token)
3cedbf72 971 (or (memq math-exp-token '(number symbol dollar hash string))
abd880c3
JB
972 (and (assoc math-expr-data '(("-") ("+") ("!") ("|") ("/")))
973 (assoc (concat "u" math-expr-data) math-expr-opers))
974 (eq (nth 2 (assoc math-expr-data math-expr-opers)) -1)
975 (assoc math-expr-data '(("(") ("[") ("{"))))))
136211a9
EZ
976
977(defun math-read-factor ()
978 (let (op)
3cedbf72 979 (cond ((eq math-exp-token 'number)
abd880c3 980 (let ((num (math-read-number math-expr-data)))
136211a9
EZ
981 (if (not num)
982 (progn
3cedbf72 983 (setq math-exp-old-pos math-exp-pos)
136211a9
EZ
984 (throw 'syntax "Bad format")))
985 (math-read-token)
986 (if (and math-read-expr-quotes
987 (consp num))
988 (list 'quote num)
989 num)))
990 ((and calc-user-parse-table
991 (setq op (calc-check-user-syntax)))
992 op)
abd880c3
JB
993 ((or (equal math-expr-data "-")
994 (equal math-expr-data "+")
995 (equal math-expr-data "!")
996 (equal math-expr-data "|")
997 (equal math-expr-data "/"))
998 (setq math-expr-data (concat "u" math-expr-data))
136211a9 999 (math-read-factor))
abd880c3 1000 ((and (setq op (assoc math-expr-data math-expr-opers))
136211a9
EZ
1001 (eq (nth 2 op) -1))
1002 (if (consp (nth 1 op))
1003 (funcall (car (nth 1 op)) op)
1004 (math-read-token)
1005 (let ((val (math-read-expr-level (nth 3 op))))
1006 (cond ((eq (nth 1 op) 'ident)
1007 val)
1008 ((and (Math-numberp val)
1009 (equal (car op) "u-"))
1010 (math-neg val))
1011 (t (list (nth 1 op) val))))))
3cedbf72 1012 ((eq math-exp-token 'symbol)
abd880c3 1013 (let ((sym (intern math-expr-data)))
136211a9 1014 (math-read-token)
abd880c3 1015 (if (equal math-expr-data calc-function-open)
136211a9
EZ
1016 (let ((f (assq sym math-expr-function-mapping)))
1017 (math-read-token)
1018 (if (consp (cdr f))
1019 (funcall (car (cdr f)) f sym)
abd880c3 1020 (let ((args (if (or (equal math-expr-data calc-function-close)
3cedbf72 1021 (eq math-exp-token 'end))
136211a9
EZ
1022 nil
1023 (math-read-expr-list))))
abd880c3 1024 (if (not (or (equal math-expr-data calc-function-close)
3cedbf72 1025 (eq math-exp-token 'end)))
136211a9
EZ
1026 (throw 'syntax "Expected `)'"))
1027 (math-read-token)
1028 (if (and (eq calc-language 'fortran) args
1029 (calc-extensions)
1030 (let ((calc-matrix-mode 'scalar))
1031 (math-known-matrixp
1032 (list 'var sym
1033 (intern
1034 (concat "var-"
1035 (symbol-name sym)))))))
1036 (math-parse-fortran-subscr sym args)
1037 (if f
1038 (setq sym (cdr f))
1039 (and (= (aref (symbol-name sym) 0) ?\\)
1040 (< (prefix-numeric-value calc-language-option)
1041 0)
1042 (setq sym (intern (substring (symbol-name sym)
1043 1))))
1044 (or (string-match "-" (symbol-name sym))
1045 (setq sym (intern
1046 (concat "calcFunc-"
1047 (symbol-name sym))))))
1048 (cons sym args)))))
1049 (if math-read-expr-quotes
1050 sym
1051 (let ((val (list 'var
1052 (intern (math-remove-dashes
1053 (symbol-name sym)))
1054 (if (string-match "-" (symbol-name sym))
1055 sym
1056 (intern (concat "var-"
1057 (symbol-name sym)))))))
1058 (let ((v (assq (nth 1 val) math-expr-variable-mapping)))
1059 (and v (setq val (if (consp (cdr v))
1060 (funcall (car (cdr v)) v val)
1061 (list 'var
1062 (intern
1063 (substring (symbol-name (cdr v))
1064 4))
1065 (cdr v))))))
1066 (while (and (memq calc-language '(c pascal maple))
abd880c3 1067 (equal math-expr-data "["))
136211a9
EZ
1068 (math-read-token)
1069 (setq val (append (list 'calcFunc-subscr val)
1070 (math-read-expr-list)))
abd880c3 1071 (if (equal math-expr-data "]")
136211a9
EZ
1072 (math-read-token)
1073 (throw 'syntax "Expected ']'")))
1074 val)))))
3cedbf72 1075 ((eq math-exp-token 'dollar)
abd880c3 1076 (let ((abs (if (> math-expr-data 0) math-expr-data (- math-expr-data))))
136211a9 1077 (if (>= (length calc-dollar-values) abs)
abd880c3 1078 (let ((num math-expr-data))
136211a9
EZ
1079 (math-read-token)
1080 (setq calc-dollar-used (max calc-dollar-used num))
1081 (math-check-complete (nth (1- abs) calc-dollar-values)))
1082 (throw 'syntax (if calc-dollar-values
1083 "Too many $'s"
1084 "$'s not allowed in this context")))))
3cedbf72 1085 ((eq math-exp-token 'hash)
136211a9
EZ
1086 (or calc-hashes-used
1087 (throw 'syntax "#'s not allowed in this context"))
1088 (calc-extensions)
abd880c3
JB
1089 (if (<= math-expr-data (length calc-arg-values))
1090 (let ((num math-expr-data))
136211a9
EZ
1091 (math-read-token)
1092 (setq calc-hashes-used (max calc-hashes-used num))
1093 (nth (1- num) calc-arg-values))
1094 (throw 'syntax "Too many # arguments")))
abd880c3 1095 ((equal math-expr-data "(")
3cedbf72 1096 (let* ((exp (let ((math-exp-keep-spaces nil))
136211a9 1097 (math-read-token)
abd880c3
JB
1098 (if (or (equal math-expr-data "\\dots")
1099 (equal math-expr-data "\\ldots"))
136211a9
EZ
1100 '(neg (var inf var-inf))
1101 (math-read-expr-level 0)))))
3cedbf72 1102 (let ((math-exp-keep-spaces nil))
136211a9 1103 (cond
abd880c3 1104 ((equal math-expr-data ",")
136211a9
EZ
1105 (progn
1106 (math-read-token)
1107 (let ((exp2 (math-read-expr-level 0)))
1108 (setq exp
1109 (if (and exp2 (Math-realp exp) (Math-realp exp2))
1110 (math-normalize (list 'cplx exp exp2))
1111 (list '+ exp (list '* exp2 '(var i var-i))))))))
abd880c3 1112 ((equal math-expr-data ";")
136211a9
EZ
1113 (progn
1114 (math-read-token)
1115 (let ((exp2 (math-read-expr-level 0)))
1116 (setq exp (if (and exp2 (Math-realp exp)
1117 (Math-anglep exp2))
1118 (math-normalize (list 'polar exp exp2))
1119 (calc-extensions)
1120 (list '* exp
1121 (list 'calcFunc-exp
1122 (list '*
1123 (math-to-radians-2 exp2)
1124 '(var i var-i)))))))))
abd880c3
JB
1125 ((or (equal math-expr-data "\\dots")
1126 (equal math-expr-data "\\ldots"))
136211a9
EZ
1127 (progn
1128 (math-read-token)
abd880c3
JB
1129 (let ((exp2 (if (or (equal math-expr-data ")")
1130 (equal math-expr-data "]")
3cedbf72 1131 (eq math-exp-token 'end))
136211a9
EZ
1132 '(var inf var-inf)
1133 (math-read-expr-level 0))))
1134 (setq exp
1135 (list 'intv
abd880c3 1136 (if (equal math-expr-data ")") 0 1)
136211a9
EZ
1137 exp
1138 exp2)))))))
abd880c3
JB
1139 (if (not (or (equal math-expr-data ")")
1140 (and (equal math-expr-data "]") (eq (car-safe exp) 'intv))
3cedbf72 1141 (eq math-exp-token 'end)))
136211a9
EZ
1142 (throw 'syntax "Expected `)'"))
1143 (math-read-token)
1144 exp))
3cedbf72 1145 ((eq math-exp-token 'string)
136211a9
EZ
1146 (calc-extensions)
1147 (math-read-string))
abd880c3 1148 ((equal math-expr-data "[")
136211a9
EZ
1149 (calc-extensions)
1150 (math-read-brackets t "]"))
abd880c3 1151 ((equal math-expr-data "{")
136211a9
EZ
1152 (calc-extensions)
1153 (math-read-brackets nil "}"))
abd880c3 1154 ((equal math-expr-data "<")
136211a9
EZ
1155 (calc-extensions)
1156 (math-read-angle-brackets))
07ff2bc8 1157 (t (throw 'syntax "Expected a number")))))
136211a9 1158
ab5796a9 1159;;; arch-tag: 5599e45d-e51e-44bb-9a20-9f4ed8c96c32
07ff2bc8 1160;;; calc-aent.el ends here