1 /** @file ginsh_parser.yy
3 * Input grammar definition for ginsh.
4 * This file must be processed with yacc/bison. */
7 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <sys/resource.h>
35 #include <sys/types.h>
43 #define YYERROR_VERBOSE 1
45 // Original readline settings
46 static int orig_completion_append_character;
47 #if (GINAC_RL_VERSION_MAJOR < 4) || (GINAC_RL_VERSION_MAJOR == 4 && GINAC_RL_VERSION_MINOR < 2)
48 static char *orig_basic_word_break_characters;
50 static const char *orig_basic_word_break_characters;
53 // Expression stack for ", "" and """
54 static void push(const ex &e);
57 // Start and end time for the time() function
58 static struct rusage start_time, end_time;
60 // Table of functions (a multimap, because one function may appear with different
61 // numbers of parameters)
62 typedef ex (*fcnp)(const exprseq &e);
63 typedef ex (*fcnp2)(const exprseq &e, int serial);
66 fcn_desc() : p(NULL), num_params(0) {}
67 fcn_desc(fcnp func, int num) : p(func), num_params(num), is_ginac(false) {}
68 fcn_desc(fcnp2 func, int num, int ser) : p((fcnp)func), num_params(num), is_ginac(true), serial(ser) {}
70 fcnp p; // Pointer to function
71 int num_params; // Number of parameters (0 = arbitrary)
72 bool is_ginac; // Flag: function is GiNaC function
73 int serial; // GiNaC function serial number (if is_ginac == true)
76 typedef multimap<string, fcn_desc> fcn_tab;
79 static fcn_tab::const_iterator find_function(const ex &sym, int req_params);
81 // Table to map help topics to help strings
82 typedef multimap<string, string> help_tab;
85 static void insert_fcn_help(const char *name, const char *str);
86 static void print_help(const string &topic);
87 static void print_help_topics(void);
90 /* Tokens (T_LITERAL means a literal value returned by the parser, but not
91 of class numeric or symbol (e.g. a constant or the FAIL object)) */
92 %token T_NUMBER T_SYMBOL T_LITERAL T_DIGITS T_QUOTE T_QUOTE2 T_QUOTE3
93 %token T_EQUAL T_NOTEQ T_LESSEQ T_GREATEREQ
95 %token T_QUIT T_WARRANTY T_PRINT T_IPRINT T_TIME T_XYZZY T_INVENTORY T_LOOK T_SCORE
97 /* Operator precedence and associativity */
100 %left '<' '>' T_LESSEQ T_GREATEREQ
124 } catch (exception &e) {
125 cerr << e.what() << endl;
132 } catch (exception &e) {
133 std::cerr << e.what() << endl;
137 | T_PRINT '(' exp ')' ';' {
139 $3.print(print_tree(std::cout));
140 } catch (exception &e) {
141 std::cerr << e.what() << endl;
145 | T_IPRINT '(' exp ')' ';' {
148 if (!e.info(info_flags::integer))
149 throw (std::invalid_argument("argument to iprint() must be an integer"));
150 long i = ex_to<numeric>(e).to_long();
152 cout << "#o" << oct << i << endl;
153 cout << "#x" << hex << i << dec << endl;
154 } catch (exception &e) {
155 cerr << e.what() << endl;
159 | '?' T_SYMBOL {print_help(ex_to<symbol>($2).get_name());}
160 | '?' T_TIME {print_help("time");}
161 | '?' '?' {print_help_topics();}
164 cout << "This program is free software; you can redistribute it and/or modify it under\n";
165 cout << "the terms of the GNU General Public License as published by the Free Software\n";
166 cout << "Foundation; either version 2 of the License, or (at your option) any later\n";
167 cout << "version.\n";
168 cout << "This program is distributed in the hope that it will be useful, but WITHOUT\n";
169 cout << "ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\n";
170 cout << "FOR A PARTICULAR PURPOSE. See the GNU General Public License for more\n";
171 cout << "details.\n";
172 cout << "You should have received a copy of the GNU General Public License along with\n";
173 cout << "this program. If not, write to the Free Software Foundation, 675 Mass Ave,\n";
174 cout << "Cambridge, MA 02139, USA.\n";
176 | T_XYZZY {cout << "Nothing happens.\n";}
177 | T_INVENTORY {cout << "You're not carrying anything.\n";}
178 | T_LOOK {cout << "You're in a twisty little maze of passages, all alike.\n";}
180 cout << "If you were to quit now, you would score ";
181 cout << (syms.size() > 350 ? 350 : syms.size());
182 cout << " out of a possible 350.\n";
184 | T_TIME {getrusage(RUSAGE_SELF, &start_time);} '(' exp ')' {
185 getrusage(RUSAGE_SELF, &end_time);
186 cout << (end_time.ru_utime.tv_sec - start_time.ru_utime.tv_sec) +
187 (end_time.ru_stime.tv_sec - start_time.ru_stime.tv_sec) +
188 double(end_time.ru_utime.tv_usec - start_time.ru_utime.tv_usec) / 1e6 +
189 double(end_time.ru_stime.tv_usec - start_time.ru_stime.tv_usec) / 1e6 << 's' << endl;
191 | error ';' {yyclearin; yyerrok;}
192 | error ':' {yyclearin; yyerrok;}
195 exp : T_NUMBER {$$ = $1;}
196 | T_SYMBOL {$$ = $1.eval();}
197 | '\'' T_SYMBOL '\'' {$$ = $2;}
198 | T_LITERAL {$$ = $1;}
199 | T_DIGITS {$$ = $1;}
200 | T_QUOTE {$$ = exstack[0];}
201 | T_QUOTE2 {$$ = exstack[1];}
202 | T_QUOTE3 {$$ = exstack[2];}
203 | T_SYMBOL '(' exprseq ')' {
204 fcn_tab::const_iterator i = find_function($1, $3.nops());
205 if (i->second.is_ginac) {
206 $$ = ((fcnp2)(i->second.p))(static_cast<const exprseq &>(*($3.bp)), i->second.serial);
208 $$ = (i->second.p)(static_cast<const exprseq &>(*($3.bp)));
211 | T_DIGITS '=' T_NUMBER {$$ = $3; Digits = ex_to<numeric>($3).to_int();}
212 | T_SYMBOL '=' exp {$$ = $3; ex_to_nonconst_symbol($1).assign($3);}
213 | exp T_EQUAL exp {$$ = $1 == $3;}
214 | exp T_NOTEQ exp {$$ = $1 != $3;}
215 | exp '<' exp {$$ = $1 < $3;}
216 | exp T_LESSEQ exp {$$ = $1 <= $3;}
217 | exp '>' exp {$$ = $1 > $3;}
218 | exp T_GREATEREQ exp {$$ = $1 >= $3;}
219 | exp '+' exp {$$ = $1 + $3;}
220 | exp '-' exp {$$ = $1 - $3;}
221 | exp '*' exp {$$ = $1 * $3;}
222 | exp '/' exp {$$ = $1 / $3;}
223 | '-' exp %prec NEG {$$ = -$2;}
224 | '+' exp %prec NEG {$$ = $2;}
225 | exp '^' exp {$$ = power($1, $3);}
226 | exp '!' {$$ = factorial($1);}
227 | '(' exp ')' {$$ = $2;}
228 | '{' list_or_empty '}' {$$ = $2;}
229 | '[' matrix ']' {$$ = lst_to_matrix(ex_to<lst>($2));}
232 exprseq : exp {$$ = exprseq($1);}
233 | exprseq ',' exp {exprseq es(static_cast<exprseq &>(*($1.bp))); $$ = es.append($3);}
236 list_or_empty: /* empty */ {$$ = *new lst;}
240 list : exp {$$ = lst($1);}
241 | list ',' exp {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($3);}
244 matrix : '[' row ']' {$$ = lst($2);}
245 | matrix ',' '[' row ']' {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($4);}
248 row : exp {$$ = lst($1);}
249 | row ',' exp {lst l(static_cast<lst &>(*($1.bp))); $$ = l.append($3);}
258 // Error print routine
261 cerr << s << " at " << yytext << endl;
265 // Push expression "e" onto the expression stack (for ", "" and """)
266 static void push(const ex &e)
268 exstack[2] = exstack[1];
269 exstack[1] = exstack[0];
278 static ex f_collect(const exprseq &e) {return e[0].collect(e[1]);}
279 static ex f_collect_distributed(const exprseq &e) {return e[0].collect(e[1], true);}
280 static ex f_degree(const exprseq &e) {return e[0].degree(e[1]);}
281 static ex f_denom(const exprseq &e) {return e[0].denom();}
282 static ex f_eval1(const exprseq &e) {return e[0].eval();}
283 static ex f_evalf1(const exprseq &e) {return e[0].evalf();}
284 static ex f_evalm(const exprseq &e) {return e[0].evalm();}
285 static ex f_expand(const exprseq &e) {return e[0].expand();}
286 static ex f_gcd(const exprseq &e) {return gcd(e[0], e[1]);}
287 static ex f_has(const exprseq &e) {return e[0].has(e[1]) ? ex(1) : ex(0);}
288 static ex f_lcm(const exprseq &e) {return lcm(e[0], e[1]);}
289 static ex f_lcoeff(const exprseq &e) {return e[0].lcoeff(e[1]);}
290 static ex f_ldegree(const exprseq &e) {return e[0].ldegree(e[1]);}
291 static ex f_lsolve(const exprseq &e) {return lsolve(e[0], e[1]);}
292 static ex f_nops(const exprseq &e) {return e[0].nops();}
293 static ex f_normal1(const exprseq &e) {return e[0].normal();}
294 static ex f_numer(const exprseq &e) {return e[0].numer();}
295 static ex f_numer_denom(const exprseq &e) {return e[0].numer_denom();}
296 static ex f_pow(const exprseq &e) {return pow(e[0], e[1]);}
297 static ex f_sqrt(const exprseq &e) {return sqrt(e[0]);}
298 static ex f_sqrfree1(const exprseq &e) {return sqrfree(e[0]);}
299 static ex f_subs2(const exprseq &e) {return e[0].subs(e[1]);}
300 static ex f_tcoeff(const exprseq &e) {return e[0].tcoeff(e[1]);}
302 #define CHECK_ARG(num, type, fcn) if (!is_a<type>(e[num])) throw(std::invalid_argument("argument " #num " to " #fcn "() must be a " #type))
304 static ex f_charpoly(const exprseq &e)
306 CHECK_ARG(0, matrix, charpoly);
307 CHECK_ARG(1, symbol, charpoly);
308 return ex_to<matrix>(e[0]).charpoly(ex_to<symbol>(e[1]));
311 static ex f_coeff(const exprseq &e)
313 CHECK_ARG(2, numeric, coeff);
314 return e[0].coeff(e[1], ex_to<numeric>(e[2]).to_int());
317 static ex f_content(const exprseq &e)
319 CHECK_ARG(1, symbol, content);
320 return e[0].content(ex_to<symbol>(e[1]));
323 static ex f_decomp_rational(const exprseq &e)
325 CHECK_ARG(1, symbol, decomp_rational);
326 return decomp_rational(e[0], ex_to<symbol>(e[1]));
329 static ex f_determinant(const exprseq &e)
331 CHECK_ARG(0, matrix, determinant);
332 return ex_to<matrix>(e[0]).determinant();
335 static ex f_diag(const exprseq &e)
337 unsigned dim = e.nops();
338 matrix &m = *new matrix(dim, dim);
339 for (unsigned i=0; i<dim; i++)
340 m.set(i, i, e.op(i));
344 static ex f_diff2(const exprseq &e)
346 CHECK_ARG(1, symbol, diff);
347 return e[0].diff(ex_to<symbol>(e[1]));
350 static ex f_diff3(const exprseq &e)
352 CHECK_ARG(1, symbol, diff);
353 CHECK_ARG(2, numeric, diff);
354 return e[0].diff(ex_to<symbol>(e[1]), ex_to<numeric>(e[2]).to_int());
357 static ex f_divide(const exprseq &e)
360 if (divide(e[0], e[1], q))
366 static ex f_eval2(const exprseq &e)
368 CHECK_ARG(1, numeric, eval);
369 return e[0].eval(ex_to<numeric>(e[1]).to_int());
372 static ex f_evalf2(const exprseq &e)
374 CHECK_ARG(1, numeric, evalf);
375 return e[0].evalf(ex_to<numeric>(e[1]).to_int());
378 static ex f_find(const exprseq &e)
381 e[0].find(e[1], found);
385 static ex f_inverse(const exprseq &e)
387 CHECK_ARG(0, matrix, inverse);
388 return ex_to<matrix>(e[0]).inverse();
391 static ex f_is(const exprseq &e)
393 CHECK_ARG(0, relational, is);
394 return (bool)ex_to<relational>(e[0]) ? ex(1) : ex(0);
397 class apply_map_function : public map_function {
400 apply_map_function(const ex & a) : apply(a) {}
401 virtual ~apply_map_function() {}
402 ex operator()(const ex & e) { return apply.subs(wild() == e, true); }
405 static ex f_map(const exprseq &e)
407 apply_map_function fcn(e[1]);
408 return e[0].map(fcn);
411 static ex f_match(const exprseq &e)
414 if (e[0].match(e[1], repl_lst))
420 static ex f_normal2(const exprseq &e)
422 CHECK_ARG(1, numeric, normal);
423 return e[0].normal(ex_to<numeric>(e[1]).to_int());
426 static ex f_op(const exprseq &e)
428 CHECK_ARG(1, numeric, op);
429 int n = ex_to<numeric>(e[1]).to_int();
430 if (n < 0 || n >= (int)e[0].nops())
431 throw(std::out_of_range("second argument to op() is out of range"));
435 static ex f_prem(const exprseq &e)
437 CHECK_ARG(2, symbol, prem);
438 return prem(e[0], e[1], ex_to<symbol>(e[2]));
441 static ex f_primpart(const exprseq &e)
443 CHECK_ARG(1, symbol, primpart);
444 return e[0].primpart(ex_to<symbol>(e[1]));
447 static ex f_quo(const exprseq &e)
449 CHECK_ARG(2, symbol, quo);
450 return quo(e[0], e[1], ex_to<symbol>(e[2]));
453 static ex f_rem(const exprseq &e)
455 CHECK_ARG(2, symbol, rem);
456 return rem(e[0], e[1], ex_to<symbol>(e[2]));
459 static ex f_series(const exprseq &e)
461 CHECK_ARG(2, numeric, series);
462 return e[0].series(e[1], ex_to<numeric>(e[2]).to_int());
465 static ex f_sqrfree2(const exprseq &e)
467 CHECK_ARG(1, lst, sqrfree);
468 return sqrfree(e[0], ex_to<lst>(e[1]));
471 static ex f_subs3(const exprseq &e)
473 CHECK_ARG(1, lst, subs);
474 CHECK_ARG(2, lst, subs);
475 return e[0].subs(ex_to<lst>(e[1]), ex_to<lst>(e[2]));
478 static ex f_trace(const exprseq &e)
480 CHECK_ARG(0, matrix, trace);
481 return ex_to<matrix>(e[0]).trace();
484 static ex f_transpose(const exprseq &e)
486 CHECK_ARG(0, matrix, transpose);
487 return ex_to<matrix>(e[0]).transpose();
490 static ex f_unassign(const exprseq &e)
492 CHECK_ARG(0, symbol, unassign);
493 ex_to_nonconst_symbol(e[0]).unassign();
497 static ex f_unit(const exprseq &e)
499 CHECK_ARG(1, symbol, unit);
500 return e[0].unit(ex_to<symbol>(e[1]));
503 static ex f_dummy(const exprseq &e)
505 throw(std::logic_error("dummy function called (shouldn't happen)"));
508 // Tables for initializing the "fcns" map and the function help topics
514 static const fcn_init builtin_fcns[] = {
515 {"charpoly", fcn_desc(f_charpoly, 2)},
516 {"coeff", fcn_desc(f_coeff, 3)},
517 {"collect", fcn_desc(f_collect, 2)},
518 {"collect_distributed", fcn_desc(f_collect_distributed, 2)},
519 {"content", fcn_desc(f_content, 2)},
520 {"decomp_rational", fcn_desc(f_decomp_rational, 2)},
521 {"degree", fcn_desc(f_degree, 2)},
522 {"denom", fcn_desc(f_denom, 1)},
523 {"determinant", fcn_desc(f_determinant, 1)},
524 {"diag", fcn_desc(f_diag, 0)},
525 {"diff", fcn_desc(f_diff2, 2)},
526 {"diff", fcn_desc(f_diff3, 3)},
527 {"divide", fcn_desc(f_divide, 2)},
528 {"eval", fcn_desc(f_eval1, 1)},
529 {"eval", fcn_desc(f_eval2, 2)},
530 {"evalf", fcn_desc(f_evalf1, 1)},
531 {"evalf", fcn_desc(f_evalf2, 2)},
532 {"evalm", fcn_desc(f_evalm, 1)},
533 {"expand", fcn_desc(f_expand, 1)},
534 {"find", fcn_desc(f_find, 2)},
535 {"gcd", fcn_desc(f_gcd, 2)},
536 {"has", fcn_desc(f_has, 2)},
537 {"inverse", fcn_desc(f_inverse, 1)},
538 {"is", fcn_desc(f_is, 1)},
539 {"lcm", fcn_desc(f_lcm, 2)},
540 {"lcoeff", fcn_desc(f_lcoeff, 2)},
541 {"ldegree", fcn_desc(f_ldegree, 2)},
542 {"lsolve", fcn_desc(f_lsolve, 2)},
543 {"map", fcn_desc(f_map, 2)},
544 {"match", fcn_desc(f_match, 2)},
545 {"nops", fcn_desc(f_nops, 1)},
546 {"normal", fcn_desc(f_normal1, 1)},
547 {"normal", fcn_desc(f_normal2, 2)},
548 {"numer", fcn_desc(f_numer, 1)},
549 {"numer_denom", fcn_desc(f_numer_denom, 1)},
550 {"op", fcn_desc(f_op, 2)},
551 {"pow", fcn_desc(f_pow, 2)},
552 {"prem", fcn_desc(f_prem, 3)},
553 {"primpart", fcn_desc(f_primpart, 2)},
554 {"quo", fcn_desc(f_quo, 3)},
555 {"rem", fcn_desc(f_rem, 3)},
556 {"series", fcn_desc(f_series, 3)},
557 {"sqrfree", fcn_desc(f_sqrfree1, 1)},
558 {"sqrfree", fcn_desc(f_sqrfree2, 2)},
559 {"sqrt", fcn_desc(f_sqrt, 1)},
560 {"subs", fcn_desc(f_subs2, 2)},
561 {"subs", fcn_desc(f_subs3, 3)},
562 {"tcoeff", fcn_desc(f_tcoeff, 2)},
563 {"time", fcn_desc(f_dummy, 0)},
564 {"trace", fcn_desc(f_trace, 1)},
565 {"transpose", fcn_desc(f_transpose, 1)},
566 {"unassign", fcn_desc(f_unassign, 1)},
567 {"unit", fcn_desc(f_unit, 2)},
568 {NULL, fcn_desc(f_dummy, 0)} // End marker
571 struct fcn_help_init {
576 static const fcn_help_init builtin_help[] = {
577 {"acos", "inverse cosine function"},
578 {"acosh", "inverse hyperbolic cosine function"},
579 {"asin", "inverse sine function"},
580 {"asinh", "inverse hyperbolic sine function"},
581 {"atan", "inverse tangent function"},
582 {"atan2", "inverse tangent function with two arguments"},
583 {"atanh", "inverse hyperbolic tangent function"},
584 {"beta", "Beta function"},
585 {"binomial", "binomial function"},
586 {"cos", "cosine function"},
587 {"cosh", "hyperbolic cosine function"},
588 {"exp", "exponential function"},
589 {"factorial", "factorial function"},
590 {"lgamma", "natural logarithm of Gamma function"},
591 {"tgamma", "Gamma function"},
592 {"log", "natural logarithm"},
593 {"psi", "psi function\npsi(x) is the digamma function, psi(n,x) the nth polygamma function"},
594 {"sin", "sine function"},
595 {"sinh", "hyperbolic sine function"},
596 {"tan", "tangent function"},
597 {"tanh", "hyperbolic tangent function"},
598 {"zeta", "zeta function\nzeta(x) is Riemann's zeta function, zeta(n,x) its nth derivative"},
599 {"Li2", "dilogarithm"},
600 {"Li3", "trilogarithm"},
601 {"Order", "order term function (for truncated power series)"},
602 {"Derivative", "inert differential operator"},
603 {NULL, NULL} // End marker
606 #include "ginsh_extensions.h"
610 * Add functions to ginsh
613 // Functions from fcn_init array
614 static void insert_fcns(const fcn_init *p)
617 fcns.insert(make_pair(string(p->name), p->desc));
622 static ex f_ginac_function(const exprseq &es, int serial)
624 return function(serial, es).eval(1);
627 // All registered GiNaC functions
628 void GiNaC::ginsh_get_ginac_functions(void)
630 vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
633 fcns.insert(make_pair(i->get_name(), fcn_desc(f_ginac_function, i->get_nparams(), serial)));
641 * Find a function given a name and number of parameters. Throw exceptions on error.
644 static fcn_tab::const_iterator find_function(const ex &sym, int req_params)
646 const string &name = ex_to<symbol>(sym).get_name();
647 typedef fcn_tab::const_iterator I;
648 pair<I, I> b = fcns.equal_range(name);
649 if (b.first == b.second)
650 throw(std::logic_error("unknown function '" + name + "'"));
652 for (I i=b.first; i!=b.second; i++)
653 if ((i->second.num_params == 0) || (i->second.num_params == req_params))
656 throw(std::logic_error("invalid number of arguments to " + name + "()"));
661 * Insert help strings
664 // Normal help string
665 static void insert_help(const char *topic, const char *str)
667 help.insert(make_pair(string(topic), string(str)));
670 // Help string for functions, automatically generates synopsis
671 static void insert_fcn_help(const char *name, const char *str)
673 typedef fcn_tab::const_iterator I;
674 pair<I, I> b = fcns.equal_range(name);
675 if (b.first != b.second) {
676 string help_str = string(name) + "(";
677 for (int i=0; i<b.first->second.num_params; i++) {
680 help_str += "expression";
684 help.insert(make_pair(string(name), help_str));
688 // Help strings for functions from fcn_help_init array
689 static void insert_help(const fcn_help_init *p)
692 insert_fcn_help(p->name, p->help);
702 // Help for a given topic
703 static void print_help(const string &topic)
705 typedef help_tab::const_iterator I;
706 pair<I, I> b = help.equal_range(topic);
707 if (b.first == b.second)
708 cout << "no help for '" << topic << "'\n";
710 for (I i=b.first; i!=b.second; i++)
711 cout << i->second << endl;
715 // List of help topics
716 static void print_help_topics(void)
718 cout << "Available help topics:\n";
719 help_tab::const_iterator i;
720 string last_name = string("*");
722 for (i=help.begin(); i!=help.end(); i++) {
723 // Don't print duplicates
724 if (i->first != last_name) {
729 last_name = i->first;
732 cout << "\nTo get help for a certain topic, type ?topic\n";
737 * Function name completion functions for readline
740 static char *fcn_generator(const char *text, int state)
742 static int len; // Length of word to complete
743 static fcn_tab::const_iterator index; // Iterator to function being currently considered
745 // If this is a new word to complete, initialize now
747 index = fcns.begin();
751 // Return the next function which partially matches
752 while (index != fcns.end()) {
753 const char *fcn_name = index->first.c_str();
755 if (strncmp(fcn_name, text, len) == 0)
756 return strdup(fcn_name);
761 static char **fcn_completion(const char *text, int start, int end)
763 if (rl_line_buffer[0] == '!') {
764 // For shell commands, revert back to filename completion
765 rl_completion_append_character = orig_completion_append_character;
766 rl_basic_word_break_characters = orig_basic_word_break_characters;
767 rl_completer_word_break_characters = rl_basic_word_break_characters;
768 #if (GINAC_RL_VERSION_MAJOR < 4) || (GINAC_RL_VERSION_MAJOR == 4 && GINAC_RL_VERSION_MINOR < 2)
769 return completion_matches(const_cast<char *>(text), (CPFunction *)filename_completion_function);
771 return rl_completion_matches(text, rl_filename_completion_function);
774 // Otherwise, complete function names
775 rl_completion_append_character = '(';
776 rl_basic_word_break_characters = " \t\n\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~";
777 rl_completer_word_break_characters = rl_basic_word_break_characters;
778 #if (GINAC_RL_VERSION_MAJOR < 4) || (GINAC_RL_VERSION_MAJOR == 4 && GINAC_RL_VERSION_MINOR < 2)
779 return completion_matches(const_cast<char *>(text), (CPFunction *)fcn_generator);
781 return rl_completion_matches(text, fcn_generator);
788 cout << "ginsh - GiNaC Interactive Shell (" << PACKAGE << " V" << VERSION << ")" << endl;
789 cout << " __, _______ Copyright (C) 1999-2001 Johannes Gutenberg University Mainz,\n"
790 << " (__) * | Germany. This is free software with ABSOLUTELY NO WARRANTY.\n"
791 << " ._) i N a C | You are welcome to redistribute it under certain conditions.\n"
792 << "<-------------' For details type `warranty;'.\n" << endl;
793 cout << "Type ?? for a list of help topics." << endl;
800 int main(int argc, char **argv)
802 // Print banner in interactive mode
806 // Init function table
807 insert_fcns(builtin_fcns);
808 insert_fcns(extended_fcns);
809 ginsh_get_ginac_functions();
811 // Init help for operators (automatically generated from man page)
812 insert_help("operators", "Operators in falling order of precedence:");
813 #include "ginsh_op_help.c"
815 // Init help for built-in functions (automatically generated from man page)
816 #include "ginsh_fcn_help.c"
818 // Help for GiNaC functions is added manually
819 insert_help(builtin_help);
820 insert_help(extended_help);
822 // Init readline completer
823 rl_readline_name = argv[0];
824 #if (GINAC_RL_VERSION_MAJOR < 4) || (GINAC_RL_VERSION_MAJOR == 4 && GINAC_RL_VERSION_MINOR < 2)
825 rl_attempted_completion_function = (CPPFunction *)fcn_completion;
827 rl_attempted_completion_function = fcn_completion;
829 orig_completion_append_character = rl_completion_append_character;
830 orig_basic_word_break_characters = rl_basic_word_break_characters;
832 // Init input file list, open first file
833 num_files = argc - 1;
834 file_list = argv + 1;
836 yyin = fopen(*file_list, "r");
838 cerr << "Can't open " << *file_list << endl;
845 // Parse input, catch all remaining exceptions
849 } catch (exception &e) {
850 cerr << e.what() << endl;