]> code.delx.au - gnu-emacs/blob - lisp/calc/calc-lang.el
Add a provide statement.
[gnu-emacs] / lisp / calc / calc-lang.el
1 ;;; calc-lang.el --- calc language functions
2
3 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc.
4
5 ;; Author: David Gillespie <daveg@synaptics.com>
6 ;; Maintainer: Jay Belanger <belanger@truman.edu>
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
25 ;;; Commentary:
26
27 ;;; Code:
28
29
30 ;; This file is autoloaded from calc-ext.el.
31 (require 'calc-ext)
32
33 (require 'calc-macs)
34
35 (defun calc-Need-calc-lang () nil)
36
37
38 ;;; Alternate entry/display languages.
39
40 (defun calc-set-language (lang &optional option no-refresh)
41 (setq math-expr-opers (or (get lang 'math-oper-table) math-standard-opers)
42 math-expr-function-mapping (get lang 'math-function-table)
43 math-expr-variable-mapping (get lang 'math-variable-table)
44 calc-language-input-filter (get lang 'math-input-filter)
45 calc-language-output-filter (get lang 'math-output-filter)
46 calc-vector-brackets (or (get lang 'math-vector-brackets) "[]")
47 calc-complex-format (get lang 'math-complex-format)
48 calc-radix-formatter (get lang 'math-radix-formatter)
49 calc-function-open (or (get lang 'math-function-open) "(")
50 calc-function-close (or (get lang 'math-function-close) ")"))
51 (if no-refresh
52 (setq calc-language lang
53 calc-language-option option)
54 (calc-change-mode '(calc-language calc-language-option)
55 (list lang option) t)))
56
57 (defun calc-normal-language ()
58 (interactive)
59 (calc-wrapper
60 (calc-set-language nil)
61 (message "Normal language mode")))
62
63 (defun calc-flat-language ()
64 (interactive)
65 (calc-wrapper
66 (calc-set-language 'flat)
67 (message "Flat language mode (all stack entries shown on one line)")))
68
69 (defun calc-big-language ()
70 (interactive)
71 (calc-wrapper
72 (calc-set-language 'big)
73 (message "\"Big\" language mode")))
74
75 (defun calc-unformatted-language ()
76 (interactive)
77 (calc-wrapper
78 (calc-set-language 'unform)
79 (message "Unformatted language mode")))
80
81
82 (defun calc-c-language ()
83 (interactive)
84 (calc-wrapper
85 (calc-set-language 'c)
86 (message "`C' language mode")))
87
88 (put 'c 'math-oper-table
89 '( ( "u+" ident -1 1000 )
90 ( "u-" neg -1 1000 )
91 ( "u!" calcFunc-lnot -1 1000 )
92 ( "~" calcFunc-not -1 1000 )
93 ( "*" * 190 191 )
94 ( "/" / 190 191 )
95 ( "%" % 190 191 )
96 ( "+" + 180 181 )
97 ( "-" - 180 181 )
98 ( "<<" calcFunc-lsh 170 171 )
99 ( ">>" calcFunc-rsh 170 171 )
100 ( "<" calcFunc-lt 160 161 )
101 ( ">" calcFunc-gt 160 161 )
102 ( "<=" calcFunc-leq 160 161 )
103 ( ">=" calcFunc-geq 160 161 )
104 ( "==" calcFunc-eq 150 151 )
105 ( "!=" calcFunc-neq 150 151 )
106 ( "&" calcFunc-and 140 141 )
107 ( "^" calcFunc-xor 131 130 )
108 ( "|" calcFunc-or 120 121 )
109 ( "&&" calcFunc-land 110 111 )
110 ( "||" calcFunc-lor 100 101 )
111 ( "?" (math-read-if) 91 90 )
112 ( "!!!" calcFunc-pnot -1 88 )
113 ( "&&&" calcFunc-pand 85 86 )
114 ( "|||" calcFunc-por 75 76 )
115 ( "=" calcFunc-assign 51 50 )
116 ( ":=" calcFunc-assign 51 50 )
117 ( "::" calcFunc-condition 45 46 ))) ; should support full assignments
118
119 (put 'c 'math-function-table
120 '( ( acos . calcFunc-arccos )
121 ( acosh . calcFunc-arccosh )
122 ( asin . calcFunc-arcsin )
123 ( asinh . calcFunc-arcsinh )
124 ( atan . calcFunc-arctan )
125 ( atan2 . calcFunc-arctan2 )
126 ( atanh . calcFunc-arctanh )))
127
128 (put 'c 'math-variable-table
129 '( ( M_PI . var-pi )
130 ( M_E . var-e )))
131
132 (put 'c 'math-vector-brackets "{}")
133
134 (put 'c 'math-radix-formatter
135 (function (lambda (r s)
136 (if (= r 16) (format "0x%s" s)
137 (if (= r 8) (format "0%s" s)
138 (format "%d#%s" r s))))))
139
140
141 (defun calc-pascal-language (n)
142 (interactive "P")
143 (calc-wrapper
144 (and n (setq n (prefix-numeric-value n)))
145 (calc-set-language 'pascal n)
146 (message (if (and n (/= n 0))
147 (if (> n 0)
148 "Pascal language mode (all uppercase)"
149 "Pascal language mode (all lowercase)")
150 "Pascal language mode"))))
151
152 (put 'pascal 'math-oper-table
153 '( ( "not" calcFunc-lnot -1 1000 )
154 ( "*" * 190 191 )
155 ( "/" / 190 191 )
156 ( "and" calcFunc-and 190 191 )
157 ( "div" calcFunc-idiv 190 191 )
158 ( "mod" % 190 191 )
159 ( "u+" ident -1 185 )
160 ( "u-" neg -1 185 )
161 ( "+" + 180 181 )
162 ( "-" - 180 181 )
163 ( "or" calcFunc-or 180 181 )
164 ( "xor" calcFunc-xor 180 181 )
165 ( "shl" calcFunc-lsh 180 181 )
166 ( "shr" calcFunc-rsh 180 181 )
167 ( "in" calcFunc-in 160 161 )
168 ( "<" calcFunc-lt 160 161 )
169 ( ">" calcFunc-gt 160 161 )
170 ( "<=" calcFunc-leq 160 161 )
171 ( ">=" calcFunc-geq 160 161 )
172 ( "=" calcFunc-eq 160 161 )
173 ( "<>" calcFunc-neq 160 161 )
174 ( "!!!" calcFunc-pnot -1 85 )
175 ( "&&&" calcFunc-pand 80 81 )
176 ( "|||" calcFunc-por 75 76 )
177 ( ":=" calcFunc-assign 51 50 )
178 ( "::" calcFunc-condition 45 46 )))
179
180 (put 'pascal 'math-input-filter 'calc-input-case-filter)
181 (put 'pascal 'math-output-filter 'calc-output-case-filter)
182
183 (put 'pascal 'math-radix-formatter
184 (function (lambda (r s)
185 (if (= r 16) (format "$%s" s)
186 (format "%d#%s" r s)))))
187
188 (defun calc-input-case-filter (str)
189 (cond ((or (null calc-language-option) (= calc-language-option 0))
190 str)
191 (t
192 (downcase str))))
193
194 (defun calc-output-case-filter (str)
195 (cond ((or (null calc-language-option) (= calc-language-option 0))
196 str)
197 ((> calc-language-option 0)
198 (upcase str))
199 (t
200 (downcase str))))
201
202
203 (defun calc-fortran-language (n)
204 (interactive "P")
205 (calc-wrapper
206 (and n (setq n (prefix-numeric-value n)))
207 (calc-set-language 'fortran n)
208 (message (if (and n (/= n 0))
209 (if (> n 0)
210 "FORTRAN language mode (all uppercase)"
211 "FORTRAN language mode (all lowercase)")
212 "FORTRAN language mode"))))
213
214 (put 'fortran 'math-oper-table
215 '( ( "u/" (math-parse-fortran-vector) -1 1 )
216 ( "/" (math-parse-fortran-vector-end) 1 -1 )
217 ( "**" ^ 201 200 )
218 ( "u+" ident -1 191 )
219 ( "u-" neg -1 191 )
220 ( "*" * 190 191 )
221 ( "/" / 190 191 )
222 ( "+" + 180 181 )
223 ( "-" - 180 181 )
224 ( ".LT." calcFunc-lt 160 161 )
225 ( ".GT." calcFunc-gt 160 161 )
226 ( ".LE." calcFunc-leq 160 161 )
227 ( ".GE." calcFunc-geq 160 161 )
228 ( ".EQ." calcFunc-eq 160 161 )
229 ( ".NE." calcFunc-neq 160 161 )
230 ( ".NOT." calcFunc-lnot -1 121 )
231 ( ".AND." calcFunc-land 110 111 )
232 ( ".OR." calcFunc-lor 100 101 )
233 ( "!!!" calcFunc-pnot -1 85 )
234 ( "&&&" calcFunc-pand 80 81 )
235 ( "|||" calcFunc-por 75 76 )
236 ( "=" calcFunc-assign 51 50 )
237 ( ":=" calcFunc-assign 51 50 )
238 ( "::" calcFunc-condition 45 46 )))
239
240 (put 'fortran 'math-vector-brackets "//")
241
242 (put 'fortran 'math-function-table
243 '( ( acos . calcFunc-arccos )
244 ( acosh . calcFunc-arccosh )
245 ( aimag . calcFunc-im )
246 ( aint . calcFunc-ftrunc )
247 ( asin . calcFunc-arcsin )
248 ( asinh . calcFunc-arcsinh )
249 ( atan . calcFunc-arctan )
250 ( atan2 . calcFunc-arctan2 )
251 ( atanh . calcFunc-arctanh )
252 ( conjg . calcFunc-conj )
253 ( log . calcFunc-ln )
254 ( nint . calcFunc-round )
255 ( real . calcFunc-re )))
256
257 (put 'fortran 'math-input-filter 'calc-input-case-filter)
258 (put 'fortran 'math-output-filter 'calc-output-case-filter)
259
260 ;; The next few variables are local to math-read-exprs in calc-aent.el
261 ;; and math-read-expr in calc-ext.el, but are set in functions they call.
262
263 (defvar math-exp-token)
264 (defvar math-expr-data)
265 (defvar math-exp-old-pos)
266
267 (defvar math-parsing-fortran-vector nil)
268 (defun math-parse-fortran-vector (op)
269 (let ((math-parsing-fortran-vector '(end . "\000")))
270 (prog1
271 (math-read-brackets t "]")
272 (setq math-exp-token (car math-parsing-fortran-vector)
273 math-expr-data (cdr math-parsing-fortran-vector)))))
274
275 (defun math-parse-fortran-vector-end (x op)
276 (if math-parsing-fortran-vector
277 (progn
278 (setq math-parsing-fortran-vector (cons math-exp-token math-expr-data)
279 math-exp-token 'end
280 math-expr-data "\000")
281 x)
282 (throw 'syntax "Unmatched closing `/'")))
283
284 (defun math-parse-fortran-subscr (sym args)
285 (setq sym (math-build-var-name sym))
286 (while args
287 (setq sym (list 'calcFunc-subscr sym (car args))
288 args (cdr args)))
289 sym)
290
291
292 (defun calc-tex-language (n)
293 (interactive "P")
294 (calc-wrapper
295 (and n (setq n (prefix-numeric-value n)))
296 (calc-set-language 'tex n)
297 (message (if (and n (/= n 0))
298 (if (> n 0)
299 "TeX language mode with \\hbox{func}(\\hbox{var})"
300 "TeX language mode with \\func{\\hbox{var}}")
301 "TeX language mode"))))
302
303 (put 'tex 'math-oper-table
304 '( ( "u+" ident -1 1000 )
305 ( "u-" neg -1 1000 )
306 ( "\\hat" calcFunc-hat -1 950 )
307 ( "\\check" calcFunc-check -1 950 )
308 ( "\\tilde" calcFunc-tilde -1 950 )
309 ( "\\acute" calcFunc-acute -1 950 )
310 ( "\\grave" calcFunc-grave -1 950 )
311 ( "\\dot" calcFunc-dot -1 950 )
312 ( "\\ddot" calcFunc-dotdot -1 950 )
313 ( "\\breve" calcFunc-breve -1 950 )
314 ( "\\bar" calcFunc-bar -1 950 )
315 ( "\\vec" calcFunc-Vec -1 950 )
316 ( "\\underline" calcFunc-under -1 950 )
317 ( "u|" calcFunc-abs -1 0 )
318 ( "|" closing 0 -1 )
319 ( "\\lfloor" calcFunc-floor -1 0 )
320 ( "\\rfloor" closing 0 -1 )
321 ( "\\lceil" calcFunc-ceil -1 0 )
322 ( "\\rceil" closing 0 -1 )
323 ( "\\pm" sdev 300 300 )
324 ( "!" calcFunc-fact 210 -1 )
325 ( "^" ^ 201 200 )
326 ( "_" calcFunc-subscr 201 200 )
327 ( "\\times" * 191 190 )
328 ( "*" * 191 190 )
329 ( "2x" * 191 190 )
330 ( "+" + 180 181 )
331 ( "-" - 180 181 )
332 ( "\\over" / 170 171 )
333 ( "/" / 170 171 )
334 ( "\\choose" calcFunc-choose 170 171 )
335 ( "\\mod" % 170 171 )
336 ( "<" calcFunc-lt 160 161 )
337 ( ">" calcFunc-gt 160 161 )
338 ( "\\leq" calcFunc-leq 160 161 )
339 ( "\\geq" calcFunc-geq 160 161 )
340 ( "=" calcFunc-eq 160 161 )
341 ( "\\neq" calcFunc-neq 160 161 )
342 ( "\\ne" calcFunc-neq 160 161 )
343 ( "\\lnot" calcFunc-lnot -1 121 )
344 ( "\\land" calcFunc-land 110 111 )
345 ( "\\lor" calcFunc-lor 100 101 )
346 ( "?" (math-read-if) 91 90 )
347 ( "!!!" calcFunc-pnot -1 85 )
348 ( "&&&" calcFunc-pand 80 81 )
349 ( "|||" calcFunc-por 75 76 )
350 ( "\\gets" calcFunc-assign 51 50 )
351 ( ":=" calcFunc-assign 51 50 )
352 ( "::" calcFunc-condition 45 46 )
353 ( "\\to" calcFunc-evalto 40 41 )
354 ( "\\to" calcFunc-evalto 40 -1 )
355 ( "=>" calcFunc-evalto 40 41 )
356 ( "=>" calcFunc-evalto 40 -1 )))
357
358 (put 'tex 'math-function-table
359 '( ( \\arccos . calcFunc-arccos )
360 ( \\arcsin . calcFunc-arcsin )
361 ( \\arctan . calcFunc-arctan )
362 ( \\arg . calcFunc-arg )
363 ( \\cos . calcFunc-cos )
364 ( \\cosh . calcFunc-cosh )
365 ( \\det . calcFunc-det )
366 ( \\exp . calcFunc-exp )
367 ( \\gcd . calcFunc-gcd )
368 ( \\ln . calcFunc-ln )
369 ( \\log . calcFunc-log10 )
370 ( \\max . calcFunc-max )
371 ( \\min . calcFunc-min )
372 ( \\tan . calcFunc-tan )
373 ( \\sin . calcFunc-sin )
374 ( \\sinh . calcFunc-sinh )
375 ( \\sqrt . calcFunc-sqrt )
376 ( \\tanh . calcFunc-tanh )
377 ( \\phi . calcFunc-totient )
378 ( \\mu . calcFunc-moebius )))
379
380 (put 'tex 'math-variable-table
381 '( ( \\pi . var-pi )
382 ( \\infty . var-inf )
383 ( \\infty . var-uinf )
384 ( \\phi . var-phi )
385 ( \\gamma . var-gamma )
386 ( \\sum . (math-parse-tex-sum calcFunc-sum) )
387 ( \\prod . (math-parse-tex-sum calcFunc-prod) )))
388
389 (put 'tex 'math-complex-format 'i)
390
391 (defun math-parse-tex-sum (f val)
392 (let (low high save)
393 (or (equal math-expr-data "_") (throw 'syntax "Expected `_'"))
394 (math-read-token)
395 (setq save math-exp-old-pos)
396 (setq low (math-read-factor))
397 (or (eq (car-safe low) 'calcFunc-eq)
398 (progn
399 (setq math-exp-old-pos (1+ save))
400 (throw 'syntax "Expected equation")))
401 (or (equal math-expr-data "^") (throw 'syntax "Expected `^'"))
402 (math-read-token)
403 (setq high (math-read-factor))
404 (list (nth 2 f) (math-read-factor) (nth 1 low) (nth 2 low) high)))
405
406 (defun math-tex-input-filter (str) ; allow parsing of 123\,456\,789.
407 (while (string-match "[0-9]\\\\,[0-9]" str)
408 (setq str (concat (substring str 0 (1+ (match-beginning 0)))
409 (substring str (1- (match-end 0))))))
410 str)
411 (put 'tex 'math-input-filter 'math-tex-input-filter)
412
413
414 (defun calc-eqn-language (n)
415 (interactive "P")
416 (calc-wrapper
417 (calc-set-language 'eqn)
418 (message "Eqn language mode")))
419
420 (put 'eqn 'math-oper-table
421 '( ( "u+" ident -1 1000 )
422 ( "u-" neg -1 1000 )
423 ( "prime" (math-parse-eqn-prime) 950 -1 )
424 ( "prime" calcFunc-Prime 950 -1 )
425 ( "dot" calcFunc-dot 950 -1 )
426 ( "dotdot" calcFunc-dotdot 950 -1 )
427 ( "hat" calcFunc-hat 950 -1 )
428 ( "tilde" calcFunc-tilde 950 -1 )
429 ( "vec" calcFunc-Vec 950 -1 )
430 ( "dyad" calcFunc-dyad 950 -1 )
431 ( "bar" calcFunc-bar 950 -1 )
432 ( "under" calcFunc-under 950 -1 )
433 ( "sub" calcFunc-subscr 931 930 )
434 ( "sup" ^ 921 920 )
435 ( "sqrt" calcFunc-sqrt -1 910 )
436 ( "over" / 900 901 )
437 ( "u|" calcFunc-abs -1 0 )
438 ( "|" closing 0 -1 )
439 ( "left floor" calcFunc-floor -1 0 )
440 ( "right floor" closing 0 -1 )
441 ( "left ceil" calcFunc-ceil -1 0 )
442 ( "right ceil" closing 0 -1 )
443 ( "+-" sdev 300 300 )
444 ( "!" calcFunc-fact 210 -1 )
445 ( "times" * 191 190 )
446 ( "*" * 191 190 )
447 ( "2x" * 191 190 )
448 ( "/" / 180 181 )
449 ( "%" % 180 181 )
450 ( "+" + 170 171 )
451 ( "-" - 170 171 )
452 ( "<" calcFunc-lt 160 161 )
453 ( ">" calcFunc-gt 160 161 )
454 ( "<=" calcFunc-leq 160 161 )
455 ( ">=" calcFunc-geq 160 161 )
456 ( "=" calcFunc-eq 160 161 )
457 ( "==" calcFunc-eq 160 161 )
458 ( "!=" calcFunc-neq 160 161 )
459 ( "u!" calcFunc-lnot -1 121 )
460 ( "&&" calcFunc-land 110 111 )
461 ( "||" calcFunc-lor 100 101 )
462 ( "?" (math-read-if) 91 90 )
463 ( "!!!" calcFunc-pnot -1 85 )
464 ( "&&&" calcFunc-pand 80 81 )
465 ( "|||" calcFunc-por 75 76 )
466 ( "<-" calcFunc-assign 51 50 )
467 ( ":=" calcFunc-assign 51 50 )
468 ( "::" calcFunc-condition 45 46 )
469 ( "->" calcFunc-evalto 40 41 )
470 ( "->" calcFunc-evalto 40 -1 )
471 ( "=>" calcFunc-evalto 40 41 )
472 ( "=>" calcFunc-evalto 40 -1 )))
473
474 (put 'eqn 'math-function-table
475 '( ( arc\ cos . calcFunc-arccos )
476 ( arc\ cosh . calcFunc-arccosh )
477 ( arc\ sin . calcFunc-arcsin )
478 ( arc\ sinh . calcFunc-arcsinh )
479 ( arc\ tan . calcFunc-arctan )
480 ( arc\ tanh . calcFunc-arctanh )
481 ( GAMMA . calcFunc-gamma )
482 ( phi . calcFunc-totient )
483 ( mu . calcFunc-moebius )
484 ( matrix . (math-parse-eqn-matrix) )))
485
486 (put 'eqn 'math-variable-table
487 '( ( inf . var-uinf )))
488
489 (put 'eqn 'math-complex-format 'i)
490
491 (defun math-parse-eqn-matrix (f sym)
492 (let ((vec nil))
493 (while (assoc math-expr-data '(("ccol") ("lcol") ("rcol")))
494 (math-read-token)
495 (or (equal math-expr-data calc-function-open)
496 (throw 'syntax "Expected `{'"))
497 (math-read-token)
498 (setq vec (cons (cons 'vec (math-read-expr-list)) vec))
499 (or (equal math-expr-data calc-function-close)
500 (throw 'syntax "Expected `}'"))
501 (math-read-token))
502 (or (equal math-expr-data calc-function-close)
503 (throw 'syntax "Expected `}'"))
504 (math-read-token)
505 (math-transpose (cons 'vec (nreverse vec)))))
506
507 (defun math-parse-eqn-prime (x sym)
508 (if (eq (car-safe x) 'var)
509 (if (equal math-expr-data calc-function-open)
510 (progn
511 (math-read-token)
512 (let ((args (if (or (equal math-expr-data calc-function-close)
513 (eq math-exp-token 'end))
514 nil
515 (math-read-expr-list))))
516 (if (not (or (equal math-expr-data calc-function-close)
517 (eq math-exp-token 'end)))
518 (throw 'syntax "Expected `)'"))
519 (math-read-token)
520 (cons (intern (format "calcFunc-%s'" (nth 1 x))) args)))
521 (list 'var
522 (intern (concat (symbol-name (nth 1 x)) "'"))
523 (intern (concat (symbol-name (nth 2 x)) "'"))))
524 (list 'calcFunc-Prime x)))
525
526
527 (defun calc-mathematica-language ()
528 (interactive)
529 (calc-wrapper
530 (calc-set-language 'math)
531 (message "Mathematica language mode")))
532
533 (put 'math 'math-oper-table
534 '( ( "[[" (math-read-math-subscr) 250 -1 )
535 ( "!" calcFunc-fact 210 -1 )
536 ( "!!" calcFunc-dfact 210 -1 )
537 ( "^" ^ 201 200 )
538 ( "u+" ident -1 197 )
539 ( "u-" neg -1 197 )
540 ( "/" / 195 196 )
541 ( "*" * 190 191 )
542 ( "2x" * 190 191 )
543 ( "+" + 180 181 )
544 ( "-" - 180 181 )
545 ( "<" calcFunc-lt 160 161 )
546 ( ">" calcFunc-gt 160 161 )
547 ( "<=" calcFunc-leq 160 161 )
548 ( ">=" calcFunc-geq 160 161 )
549 ( "==" calcFunc-eq 150 151 )
550 ( "!=" calcFunc-neq 150 151 )
551 ( "u!" calcFunc-lnot -1 121 )
552 ( "&&" calcFunc-land 110 111 )
553 ( "||" calcFunc-lor 100 101 )
554 ( "!!!" calcFunc-pnot -1 85 )
555 ( "&&&" calcFunc-pand 80 81 )
556 ( "|||" calcFunc-por 75 76 )
557 ( ":=" calcFunc-assign 51 50 )
558 ( "=" calcFunc-assign 51 50 )
559 ( "->" calcFunc-assign 51 50 )
560 ( ":>" calcFunc-assign 51 50 )
561 ( "::" calcFunc-condition 45 46 )
562 ))
563
564 (put 'math 'math-function-table
565 '( ( Abs . calcFunc-abs )
566 ( ArcCos . calcFunc-arccos )
567 ( ArcCosh . calcFunc-arccosh )
568 ( ArcSin . calcFunc-arcsin )
569 ( ArcSinh . calcFunc-arcsinh )
570 ( ArcTan . calcFunc-arctan )
571 ( ArcTanh . calcFunc-arctanh )
572 ( Arg . calcFunc-arg )
573 ( Binomial . calcFunc-choose )
574 ( Ceiling . calcFunc-ceil )
575 ( Conjugate . calcFunc-conj )
576 ( Cos . calcFunc-cos )
577 ( Cosh . calcFunc-cosh )
578 ( D . calcFunc-deriv )
579 ( Dt . calcFunc-tderiv )
580 ( Det . calcFunc-det )
581 ( Exp . calcFunc-exp )
582 ( EulerPhi . calcFunc-totient )
583 ( Floor . calcFunc-floor )
584 ( Gamma . calcFunc-gamma )
585 ( GCD . calcFunc-gcd )
586 ( If . calcFunc-if )
587 ( Im . calcFunc-im )
588 ( Inverse . calcFunc-inv )
589 ( Integrate . calcFunc-integ )
590 ( Join . calcFunc-vconcat )
591 ( LCM . calcFunc-lcm )
592 ( Log . calcFunc-ln )
593 ( Max . calcFunc-max )
594 ( Min . calcFunc-min )
595 ( Mod . calcFunc-mod )
596 ( MoebiusMu . calcFunc-moebius )
597 ( Random . calcFunc-random )
598 ( Round . calcFunc-round )
599 ( Re . calcFunc-re )
600 ( Sign . calcFunc-sign )
601 ( Sin . calcFunc-sin )
602 ( Sinh . calcFunc-sinh )
603 ( Sqrt . calcFunc-sqrt )
604 ( Tan . calcFunc-tan )
605 ( Tanh . calcFunc-tanh )
606 ( Transpose . calcFunc-trn )
607 ( Length . calcFunc-vlen )
608 ))
609
610 (put 'math 'math-variable-table
611 '( ( I . var-i )
612 ( Pi . var-pi )
613 ( E . var-e )
614 ( GoldenRatio . var-phi )
615 ( EulerGamma . var-gamma )
616 ( Infinity . var-inf )
617 ( ComplexInfinity . var-uinf )
618 ( Indeterminate . var-nan )
619 ))
620
621 (put 'math 'math-vector-brackets "{}")
622 (put 'math 'math-complex-format 'I)
623 (put 'math 'math-function-open "[")
624 (put 'math 'math-function-close "]")
625
626 (put 'math 'math-radix-formatter
627 (function (lambda (r s) (format "%d^^%s" r s))))
628
629 (defun math-read-math-subscr (x op)
630 (let ((idx (math-read-expr-level 0)))
631 (or (and (equal math-expr-data "]")
632 (progn
633 (math-read-token)
634 (equal math-expr-data "]")))
635 (throw 'syntax "Expected ']]'"))
636 (math-read-token)
637 (list 'calcFunc-subscr x idx)))
638
639
640 (defun calc-maple-language ()
641 (interactive)
642 (calc-wrapper
643 (calc-set-language 'maple)
644 (message "Maple language mode")))
645
646 (put 'maple 'math-oper-table
647 '( ( "matrix" ident -1 300 )
648 ( "MATRIX" ident -1 300 )
649 ( "!" calcFunc-fact 210 -1 )
650 ( "^" ^ 201 200 )
651 ( "**" ^ 201 200 )
652 ( "u+" ident -1 197 )
653 ( "u-" neg -1 197 )
654 ( "/" / 191 192 )
655 ( "*" * 191 192 )
656 ( "intersect" calcFunc-vint 191 192 )
657 ( "+" + 180 181 )
658 ( "-" - 180 181 )
659 ( "union" calcFunc-vunion 180 181 )
660 ( "minus" calcFunc-vdiff 180 181 )
661 ( "mod" % 170 170 )
662 ( ".." (math-read-maple-dots) 165 165 )
663 ( "\\dots" (math-read-maple-dots) 165 165 )
664 ( "<" calcFunc-lt 160 160 )
665 ( ">" calcFunc-gt 160 160 )
666 ( "<=" calcFunc-leq 160 160 )
667 ( ">=" calcFunc-geq 160 160 )
668 ( "=" calcFunc-eq 160 160 )
669 ( "<>" calcFunc-neq 160 160 )
670 ( "not" calcFunc-lnot -1 121 )
671 ( "and" calcFunc-land 110 111 )
672 ( "or" calcFunc-lor 100 101 )
673 ( "!!!" calcFunc-pnot -1 85 )
674 ( "&&&" calcFunc-pand 80 81 )
675 ( "|||" calcFunc-por 75 76 )
676 ( ":=" calcFunc-assign 51 50 )
677 ( "::" calcFunc-condition 45 46 )
678 ))
679
680 (put 'maple 'math-function-table
681 '( ( bernoulli . calcFunc-bern )
682 ( binomial . calcFunc-choose )
683 ( diff . calcFunc-deriv )
684 ( GAMMA . calcFunc-gamma )
685 ( ifactor . calcFunc-prfac )
686 ( igcd . calcFunc-gcd )
687 ( ilcm . calcFunc-lcm )
688 ( int . calcFunc-integ )
689 ( modp . % )
690 ( irem . % )
691 ( iquo . calcFunc-idiv )
692 ( isprime . calcFunc-prime )
693 ( length . calcFunc-vlen )
694 ( member . calcFunc-in )
695 ( crossprod . calcFunc-cross )
696 ( inverse . calcFunc-inv )
697 ( trace . calcFunc-tr )
698 ( transpose . calcFunc-trn )
699 ( vectdim . calcFunc-vlen )
700 ))
701
702 (put 'maple 'math-variable-table
703 '( ( I . var-i )
704 ( Pi . var-pi )
705 ( E . var-e )
706 ( infinity . var-inf )
707 ( infinity . var-uinf )
708 ( infinity . var-nan )
709 ))
710
711 (put 'maple 'math-complex-format 'I)
712
713 (defun math-read-maple-dots (x op)
714 (list 'intv 3 x (math-read-expr-level (nth 3 op))))
715
716
717 ;; The variable math-read-big-lines is local to math-read-big-expr in
718 ;; calc-ext.el, but is used by math-read-big-rec, math-read-big-char,
719 ;; math-read-big-emptyp, math-read-big-error and math-read-big-balance,
720 ;; which are called (directly and indirectly) by math-read-big-expr.
721 ;; It is also local to math-read-big-bigp in calc-ext.el, which calls
722 ;; math-read-big-balance.
723 (defvar math-read-big-lines)
724
725 ;; The variables math-read-big-baseline and math-read-big-h2 are
726 ;; local to math-read-big-expr in calc-ext.el, but used by
727 ;; math-read-big-rec.
728 (defvar math-read-big-baseline)
729 (defvar math-read-big-h2)
730
731 ;; The variables math-rb-h1, math-rb-h2, math-rb-v1 and math-rb-v2
732 ;; are local to math-read-big-rec, but are used by math-read-big-char,
733 ;; math-read-big-emptyp and math-read-big-balance which are called by
734 ;; math-read-big-rec.
735 ;; math-rb-h2 is also local to math-read-big-bigp in calc-ext.el,
736 ;; which calls math-read-big-balance.
737 (defvar math-rb-h1)
738 (defvar math-rb-h2)
739 (defvar math-rb-v1)
740 (defvar math-rb-v2)
741
742 (defun math-read-big-rec (math-rb-h1 math-rb-v1 math-rb-h2 math-rb-v2
743 &optional baseline prec short)
744 (or prec (setq prec 0))
745
746 ;; Clip whitespace above or below.
747 (while (and (< math-rb-v1 math-rb-v2)
748 (math-read-big-emptyp math-rb-h1 math-rb-v1 math-rb-h2 (1+ math-rb-v1)))
749 (setq math-rb-v1 (1+ math-rb-v1)))
750 (while (and (< math-rb-v1 math-rb-v2)
751 (math-read-big-emptyp math-rb-h1 (1- math-rb-v2) math-rb-h2 math-rb-v2))
752 (setq math-rb-v2 (1- math-rb-v2)))
753
754 ;; If formula is a single line high, normal parser can handle it.
755 (if (<= math-rb-v2 (1+ math-rb-v1))
756 (if (or (<= math-rb-v2 math-rb-v1)
757 (> math-rb-h1 (length (setq math-rb-v2
758 (nth math-rb-v1 math-read-big-lines)))))
759 (math-read-big-error math-rb-h1 math-rb-v1)
760 (setq math-read-big-baseline math-rb-v1
761 math-read-big-h2 math-rb-h2
762 math-rb-v2 (nth math-rb-v1 math-read-big-lines)
763 math-rb-h2 (math-read-expr
764 (substring math-rb-v2 math-rb-h1
765 (min math-rb-h2 (length math-rb-v2)))))
766 (if (eq (car-safe math-rb-h2) 'error)
767 (math-read-big-error (+ math-rb-h1 (nth 1 math-rb-h2))
768 math-rb-v1 (nth 2 math-rb-h2))
769 math-rb-h2))
770
771 ;; Clip whitespace at left or right.
772 (while (and (< math-rb-h1 math-rb-h2)
773 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) math-rb-v2))
774 (setq math-rb-h1 (1+ math-rb-h1)))
775 (while (and (< math-rb-h1 math-rb-h2)
776 (math-read-big-emptyp (1- math-rb-h2) math-rb-v1 math-rb-h2 math-rb-v2))
777 (setq math-rb-h2 (1- math-rb-h2)))
778
779 ;; Scan to find widest left-justified "----" in the region.
780 (let* ((widest nil)
781 (widest-h2 0)
782 (lines-v1 (nthcdr math-rb-v1 math-read-big-lines))
783 (p lines-v1)
784 (v math-rb-v1)
785 (other-v nil)
786 other-char line len h)
787 (while (< v math-rb-v2)
788 (setq line (car p)
789 len (min math-rb-h2 (length line)))
790 (and (< math-rb-h1 len)
791 (/= (aref line math-rb-h1) ?\ )
792 (if (and (= (aref line math-rb-h1) ?\-)
793 ;; Make sure it's not a minus sign.
794 (or (and (< (1+ math-rb-h1) len)
795 (= (aref line (1+ math-rb-h1)) ?\-))
796 (/= (math-read-big-char math-rb-h1 (1- v)) ?\ )
797 (/= (math-read-big-char math-rb-h1 (1+ v)) ?\ )))
798 (progn
799 (setq h math-rb-h1)
800 (while (and (< (setq h (1+ h)) len)
801 (= (aref line h) ?\-)))
802 (if (> h widest-h2)
803 (setq widest v
804 widest-h2 h)))
805 (or other-v (setq other-v v other-char (aref line math-rb-h1)))))
806 (setq v (1+ v)
807 p (cdr p)))
808
809 (cond ((not (setq v other-v))
810 (math-read-big-error math-rb-h1 math-rb-v1)) ; Should never happen!
811
812 ;; Quotient.
813 (widest
814 (setq h widest-h2
815 v widest)
816 (let ((num (math-read-big-rec math-rb-h1 math-rb-v1 h v))
817 (den (math-read-big-rec math-rb-h1 (1+ v) h math-rb-v2)))
818 (setq p (if (and (math-integerp num) (math-integerp den))
819 (math-make-frac num den)
820 (list '/ num den)))))
821
822 ;; Big radical sign.
823 ((= other-char ?\\)
824 (or (= (math-read-big-char (1+ math-rb-h1) v) ?\|)
825 (math-read-big-error (1+ math-rb-h1) v "Malformed root sign"))
826 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
827 (while (= (math-read-big-char (1+ math-rb-h1) (setq v (1- v))) ?\|))
828 (or (= (math-read-big-char (setq h (+ math-rb-h1 2)) v) ?\_)
829 (math-read-big-error h v "Malformed root sign"))
830 (while (= (math-read-big-char (setq h (1+ h)) v) ?\_))
831 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
832 (math-read-big-emptyp math-rb-h1 (1+ other-v) h math-rb-v2 nil t)
833 (setq p (list 'calcFunc-sqrt (math-read-big-rec
834 (+ math-rb-h1 2) (1+ v)
835 h (1+ other-v) baseline))
836 v math-read-big-baseline))
837
838 ;; Small radical sign.
839 ((and (= other-char ?V)
840 (= (math-read-big-char (1+ math-rb-h1) (1- v)) ?\_))
841 (setq h (1+ math-rb-h1))
842 (math-read-big-emptyp math-rb-h1 math-rb-v1 h (1- v) nil t)
843 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t)
844 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
845 (while (= (math-read-big-char (setq h (1+ h)) (1- v)) ?\_))
846 (setq p (list 'calcFunc-sqrt (math-read-big-rec
847 (1+ math-rb-h1) v h (1+ v) t))
848 v math-read-big-baseline))
849
850 ;; Binomial coefficient.
851 ((and (= other-char ?\()
852 (= (math-read-big-char (1+ math-rb-h1) v) ?\ )
853 (= (string-match "( *)" (nth v math-read-big-lines)
854 math-rb-h1) math-rb-h1))
855 (setq h (match-end 0))
856 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
857 (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t)
858 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t)
859 (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t)
860 (setq p (list 'calcFunc-choose
861 (math-read-big-rec (1+ math-rb-h1) math-rb-v1 (1- h) v)
862 (math-read-big-rec (1+ math-rb-h1) (1+ v)
863 (1- h) math-rb-v2))))
864
865 ;; Minus sign.
866 ((= other-char ?\-)
867 (setq p (list 'neg (math-read-big-rec (1+ math-rb-h1) math-rb-v1
868 math-rb-h2 math-rb-v2 v 250 t))
869 v math-read-big-baseline
870 h math-read-big-h2))
871
872 ;; Parentheses.
873 ((= other-char ?\()
874 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
875 (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t)
876 (setq h (math-read-big-balance (1+ math-rb-h1) v "(" t))
877 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t)
878 (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t)
879 (let ((sep (math-read-big-char (1- h) v))
880 hmid)
881 (if (= sep ?\.)
882 (setq h (1+ h)))
883 (if (= sep ?\])
884 (math-read-big-error (1- h) v "Expected `)'"))
885 (if (= sep ?\))
886 (setq p (math-read-big-rec
887 (1+ math-rb-h1) math-rb-v1 (1- h) math-rb-v2 v))
888 (setq hmid (math-read-big-balance h v "(")
889 p (list p
890 (math-read-big-rec h math-rb-v1 (1- hmid) math-rb-v2 v))
891 h hmid)
892 (cond ((= sep ?\.)
893 (setq p (cons 'intv (cons (if (= (math-read-big-char
894 (1- h) v)
895 ?\))
896 0 1)
897 p))))
898 ((= (math-read-big-char (1- h) v) ?\])
899 (math-read-big-error (1- h) v "Expected `)'"))
900 ((= sep ?\,)
901 (or (and (math-realp (car p)) (math-realp (nth 1 p)))
902 (math-read-big-error
903 math-rb-h1 v "Complex components must be real"))
904 (setq p (cons 'cplx p)))
905 ((= sep ?\;)
906 (or (and (math-realp (car p)) (math-anglep (nth 1 p)))
907 (math-read-big-error
908 math-rb-h1 v "Complex components must be real"))
909 (setq p (cons 'polar p)))))))
910
911 ;; Matrix.
912 ((and (= other-char ?\[)
913 (or (= (math-read-big-char (setq h math-rb-h1) (1+ v)) ?\[)
914 (= (math-read-big-char (setq h (1+ h)) v) ?\[)
915 (and (= (math-read-big-char h v) ?\ )
916 (= (math-read-big-char (setq h (1+ h)) v) ?\[)))
917 (= (math-read-big-char h (1+ v)) ?\[))
918 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t)
919 (let ((vtop v)
920 (hleft h)
921 (hright nil))
922 (setq p nil)
923 (while (progn
924 (setq h (math-read-big-balance (1+ hleft) v "["))
925 (if hright
926 (or (= h hright)
927 (math-read-big-error hright v "Expected `]'"))
928 (setq hright h))
929 (setq p (cons (math-read-big-rec
930 hleft v h (1+ v)) p))
931 (and (memq (math-read-big-char h v) '(?\ ?\,))
932 (= (math-read-big-char hleft (1+ v)) ?\[)))
933 (setq v (1+ v)))
934 (or (= hleft math-rb-h1)
935 (progn
936 (if (= (math-read-big-char h v) ?\ )
937 (setq h (1+ h)))
938 (and (= (math-read-big-char h v) ?\])
939 (setq h (1+ h))))
940 (math-read-big-error (1- h) v "Expected `]'"))
941 (if (= (math-read-big-char h vtop) ?\,)
942 (setq h (1+ h)))
943 (math-read-big-emptyp math-rb-h1 (1+ v) (1- h) math-rb-v2 nil t)
944 (setq v (+ vtop (/ (- v vtop) 2))
945 p (cons 'vec (nreverse p)))))
946
947 ;; Square brackets.
948 ((= other-char ?\[)
949 (math-read-big-emptyp math-rb-h1 math-rb-v1 (1+ math-rb-h1) v nil t)
950 (math-read-big-emptyp math-rb-h1 (1+ v) (1+ math-rb-h1) math-rb-v2 nil t)
951 (setq p nil
952 h (1+ math-rb-h1))
953 (while (progn
954 (setq widest (math-read-big-balance h v "[" t))
955 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t)
956 (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t)
957 (setq p (cons (math-read-big-rec
958 h math-rb-v1 (1- widest) math-rb-v2 v) p)
959 h widest)
960 (= (math-read-big-char (1- h) v) ?\,)))
961 (setq widest (math-read-big-char (1- h) v))
962 (if (or (memq widest '(?\; ?\)))
963 (and (eq widest ?\.) (cdr p)))
964 (math-read-big-error (1- h) v "Expected `]'"))
965 (if (= widest ?\.)
966 (setq h (1+ h)
967 widest (math-read-big-balance h v "[")
968 p (nconc p (list (math-read-big-rec
969 h math-rb-v1 (1- widest) math-rb-v2 v)))
970 h widest
971 p (cons 'intv (cons (if (= (math-read-big-char (1- h) v)
972 ?\])
973 3 2)
974 p)))
975 (setq p (cons 'vec (nreverse p)))))
976
977 ;; Date form.
978 ((= other-char ?\<)
979 (setq line (nth v math-read-big-lines))
980 (string-match ">" line math-rb-h1)
981 (setq h (match-end 0))
982 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t)
983 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t)
984 (setq p (math-read-big-rec math-rb-h1 v h (1+ v) v)))
985
986 ;; Variable name or function call.
987 ((or (and (>= other-char ?a) (<= other-char ?z))
988 (and (>= other-char ?A) (<= other-char ?Z)))
989 (setq line (nth v math-read-big-lines))
990 (string-match "\\([a-zA-Z'_]+\\) *" line math-rb-h1)
991 (setq h (match-end 1)
992 widest (match-end 0)
993 p (math-match-substring line 1))
994 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t)
995 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t)
996 (if (= (math-read-big-char widest v) ?\()
997 (progn
998 (setq line (if (string-match "-" p)
999 (intern p)
1000 (intern (concat "calcFunc-" p)))
1001 h (1+ widest)
1002 p nil)
1003 (math-read-big-emptyp widest math-rb-v1 h v nil t)
1004 (math-read-big-emptyp widest (1+ v) h math-rb-v2 nil t)
1005 (while (progn
1006 (setq widest (math-read-big-balance h v "(" t))
1007 (math-read-big-emptyp (1- h) math-rb-v1 h v nil t)
1008 (math-read-big-emptyp (1- h) (1+ v) h math-rb-v2 nil t)
1009 (setq p (cons (math-read-big-rec
1010 h math-rb-v1 (1- widest) math-rb-v2 v) p)
1011 h widest)
1012 (= (math-read-big-char (1- h) v) ?\,)))
1013 (or (= (math-read-big-char (1- h) v) ?\))
1014 (math-read-big-error (1- h) v "Expected `)'"))
1015 (setq p (cons line (nreverse p))))
1016 (setq p (list 'var
1017 (intern (math-remove-dashes p))
1018 (if (string-match "-" p)
1019 (intern p)
1020 (intern (concat "var-" p)))))))
1021
1022 ;; Number.
1023 (t
1024 (setq line (nth v math-read-big-lines))
1025 (or (= (string-match "_?\\([0-9]+.?0*@ *\\)?\\([0-9]+.?0*' *\\)?\\([0-9]+\\(#\\|\\^\\^\\)[0-9a-zA-Z:]+\\|[0-9]+:[0-9:]+\\|[0-9.]+\\([eE][-+_]?[0-9]+\\)?\"?\\)?" line math-rb-h1) math-rb-h1)
1026 (math-read-big-error h v "Expected a number"))
1027 (setq h (match-end 0)
1028 p (math-read-number (math-match-substring line 0)))
1029 (math-read-big-emptyp math-rb-h1 math-rb-v1 h v nil t)
1030 (math-read-big-emptyp math-rb-h1 (1+ v) h math-rb-v2 nil t)))
1031
1032 ;; Now left term is bounded by math-rb-h1, math-rb-v1, h, math-rb-v2;
1033 ;; baseline = v.
1034 (if baseline
1035 (or (= v baseline)
1036 (math-read-big-error math-rb-h1 v "Inconsistent baseline in formula"))
1037 (setq baseline v))
1038
1039 ;; Look for superscripts or subscripts.
1040 (setq line (nth baseline math-read-big-lines)
1041 len (min math-rb-h2 (length line))
1042 widest h)
1043 (while (and (< widest len)
1044 (= (aref line widest) ?\ ))
1045 (setq widest (1+ widest)))
1046 (and (>= widest len) (setq widest math-rb-h2))
1047 (if (math-read-big-emptyp h v widest math-rb-v2)
1048 (if (math-read-big-emptyp h math-rb-v1 widest v)
1049 (setq h widest)
1050 (setq p (list '^ p (math-read-big-rec h math-rb-v1 widest v))
1051 h widest))
1052 (if (math-read-big-emptyp h math-rb-v1 widest v)
1053 (setq p (list 'calcFunc-subscr p
1054 (math-read-big-rec h v widest math-rb-v2))
1055 h widest)))
1056
1057 ;; Look for an operator name and grab additional terms.
1058 (while (and (< h len)
1059 (if (setq widest (and (math-read-big-emptyp
1060 h math-rb-v1 (1+ h) v)
1061 (math-read-big-emptyp
1062 h (1+ v) (1+ h) math-rb-v2)
1063 (string-match "<=\\|>=\\|\\+/-\\|!=\\|&&\\|||\\|:=\\|=>\\|." line h)
1064 (assoc (math-match-substring line 0)
1065 math-standard-opers)))
1066 (and (>= (nth 2 widest) prec)
1067 (setq h (match-end 0)))
1068 (and (not (eq (string-match ",\\|;\\|\\.\\.\\|)\\|\\]\\|:" line h)
1069 h))
1070 (setq widest '("2x" * 196 195)))))
1071 (cond ((eq (nth 3 widest) -1)
1072 (setq p (list (nth 1 widest) p)))
1073 ((equal (car widest) "?")
1074 (let ((y (math-read-big-rec h math-rb-v1 math-rb-h2
1075 math-rb-v2 baseline nil t)))
1076 (or (= (math-read-big-char math-read-big-h2 baseline) ?\:)
1077 (math-read-big-error math-read-big-h2 baseline "Expected `:'"))
1078 (setq p (list (nth 1 widest) p y
1079 (math-read-big-rec
1080 (1+ math-read-big-h2) math-rb-v1 math-rb-h2 math-rb-v2
1081 baseline (nth 3 widest) t))
1082 h math-read-big-h2)))
1083 (t
1084 (setq p (list (nth 1 widest) p
1085 (math-read-big-rec h math-rb-v1 math-rb-h2 math-rb-v2
1086 baseline (nth 3 widest) t))
1087 h math-read-big-h2))))
1088
1089 ;; Return all relevant information to caller.
1090 (setq math-read-big-baseline baseline
1091 math-read-big-h2 h)
1092 (or short (= math-read-big-h2 math-rb-h2)
1093 (math-read-big-error h baseline))
1094 p)))
1095
1096 (defun math-read-big-char (h v)
1097 (or (and (>= h math-rb-h1)
1098 (< h math-rb-h2)
1099 (>= v math-rb-v1)
1100 (< v math-rb-v2)
1101 (let ((line (nth v math-read-big-lines)))
1102 (and line
1103 (< h (length line))
1104 (aref line h))))
1105 ?\ ))
1106
1107 (defun math-read-big-emptyp (eh1 ev1 eh2 ev2 &optional what error)
1108 (and (< ev1 math-rb-v1) (setq ev1 math-rb-v1))
1109 (and (< eh1 math-rb-h1) (setq eh1 math-rb-h1))
1110 (and (> ev2 math-rb-v2) (setq ev2 math-rb-v2))
1111 (and (> eh2 math-rb-h2) (setq eh2 math-rb-h2))
1112 (or what (setq what ?\ ))
1113 (let ((p (nthcdr ev1 math-read-big-lines))
1114 h)
1115 (while (and (< ev1 ev2)
1116 (progn
1117 (setq h (min eh2 (length (car p))))
1118 (while (and (>= (setq h (1- h)) eh1)
1119 (= (aref (car p) h) what)))
1120 (and error (>= h eh1)
1121 (math-read-big-error h ev1 (if (stringp error)
1122 error
1123 "Whitespace expected")))
1124 (< h eh1)))
1125 (setq ev1 (1+ ev1)
1126 p (cdr p)))
1127 (>= ev1 ev2)))
1128
1129 ;; math-read-big-err-msg is local to math-read-big-expr in calc-ext.el,
1130 ;; but is used by math-read-big-error which is called (indirectly) by
1131 ;; math-read-big-expr.
1132 (defvar math-read-big-err-msg)
1133
1134 (defun math-read-big-error (h v &optional msg)
1135 (let ((pos 0)
1136 (p math-read-big-lines))
1137 (while (> v 0)
1138 (setq pos (+ pos 1 (length (car p)))
1139 p (cdr p)
1140 v (1- v)))
1141 (setq h (+ pos (min h (length (car p))))
1142 math-read-big-err-msg (list 'error h (or msg "Syntax error")))
1143 (throw 'syntax nil)))
1144
1145 (defun math-read-big-balance (h v what &optional commas)
1146 (let* ((line (nth v math-read-big-lines))
1147 (len (min math-rb-h2 (length line)))
1148 (count 1))
1149 (while (> count 0)
1150 (if (>= h len)
1151 (if what
1152 (math-read-big-error nil v (format "Unmatched `%s'" what))
1153 (setq count 0))
1154 (if (memq (aref line h) '(?\( ?\[))
1155 (setq count (1+ count))
1156 (if (if (and commas (= count 1))
1157 (or (memq (aref line h) '(?\) ?\] ?\, ?\;))
1158 (and (eq (aref line h) ?\.)
1159 (< (1+ h) len)
1160 (eq (aref line (1+ h)) ?\.)))
1161 (memq (aref line h) '(?\) ?\])))
1162 (setq count (1- count))))
1163 (setq h (1+ h))))
1164 h))
1165
1166 ;;; arch-tag: 483bfe15-f290-4fef-bb7d-ce65be687f2e
1167 ;;; calc-lang.el ends here