]> www.ginac.de Git - ginac.git/blobdiff - ginsh/ginsh_parser.yy
* Added example about series expansion.
[ginac.git] / ginsh / ginsh_parser.yy
index 52a134f599fb0a9e8fee39ab8bc482f3bfba505d..1a4e7e0ad01736861afc3cfd74a84a5c0e3fce18 100644 (file)
@@ -4,7 +4,7 @@
  *  This file must be processed with yacc/bison. */
 
 /*
- *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -125,15 +125,15 @@ line      : ';'
                try {
                        push($1);
                } catch (exception &e) {
-                       cerr << e.what() << endl;
+                       std::cerr << e.what() << endl;
                        YYERROR;
                }
        }
        | T_PRINT '(' exp ')' ';' {
                try {
-                       $3.printtree(cout);
+                       $3.print(print_tree(std::cout));
                } catch (exception &e) {
-                       cerr << e.what() << endl;
+                       std::cerr << e.what() << endl;
                        YYERROR;
                }
        }
@@ -145,13 +145,14 @@ line      : ';'
                        long i = ex_to_numeric(e).to_long();
                        cout << i << endl;
                        cout << "#o" << oct << i << endl;
-                       cout << "#x" << hex << i << endl;
+                       cout << "#x" << hex << i << dec << endl;
                } catch (exception &e) {
                        cerr << e.what() << endl;
                        YYERROR;
                }
        }
-       | '?' T_SYMBOL          {print_help(ex_to_symbol($2).getname());}
+       | '?' T_SYMBOL          {print_help(ex_to_symbol($2).get_name());}
+       | '?' T_TIME            {print_help("time");}
        | '?' '?'               {print_help_topics();}
        | T_QUIT                {YYACCEPT;}
        | T_WARRANTY {
@@ -175,6 +176,13 @@ line       : ';'
                cout << (syms.size() > 350 ? 350 : syms.size());
                cout << " out of a possible 350.\n";
        }
+       | T_TIME {getrusage(RUSAGE_SELF, &start_time);} '(' exp ')' {
+               getrusage(RUSAGE_SELF, &end_time);
+               cout << (end_time.ru_utime.tv_sec - start_time.ru_utime.tv_sec) +
+                       (end_time.ru_stime.tv_sec - start_time.ru_stime.tv_sec) +
+                        double(end_time.ru_utime.tv_usec - start_time.ru_utime.tv_usec) / 1e6 +
+                        double(end_time.ru_stime.tv_usec - start_time.ru_stime.tv_usec) / 1e6 << 's' << endl;
+       }
        | error ';'             {yyclearin; yyerrok;}
        | error ':'             {yyclearin; yyerrok;}
        ;
@@ -187,13 +195,6 @@ exp        : T_NUMBER              {$$ = $1;}
        | T_QUOTE               {$$ = exstack[0];}
        | T_QUOTE2              {$$ = exstack[1];}
        | T_QUOTE3              {$$ = exstack[2];}
-       | T_TIME {getrusage(RUSAGE_SELF, &start_time);} '(' exp ')' {
-               getrusage(RUSAGE_SELF, &end_time);
-               $$ = (end_time.ru_utime.tv_sec - start_time.ru_utime.tv_sec) +
-                    (end_time.ru_stime.tv_sec - start_time.ru_stime.tv_sec) +
-                    double(end_time.ru_utime.tv_usec - start_time.ru_utime.tv_usec) / 1e6 +
-                    double(end_time.ru_stime.tv_usec - start_time.ru_stime.tv_usec) / 1e6;
-       }
        | T_SYMBOL '(' exprseq ')' {
                fcn_tab::const_iterator i = find_function($1, $3.nops());
                if (i->second.is_ginac) {
@@ -214,14 +215,13 @@ exp       : T_NUMBER              {$$ = $1;}
        | exp '-' exp           {$$ = $1 - $3;}
        | exp '*' exp           {$$ = $1 * $3;}
        | exp '/' exp           {$$ = $1 / $3;}
-       | exp '%' exp           {$$ = $1 % $3;}
        | '-' exp %prec NEG     {$$ = -$2;}
        | '+' exp %prec NEG     {$$ = $2;}
        | exp '^' exp           {$$ = power($1, $3);}
        | exp '!'               {$$ = factorial($1);}
        | '(' exp ')'           {$$ = $2;}
        | '[' list_or_empty ']' {$$ = $2;}
-       | T_MATRIX_BEGIN matrix T_MATRIX_END    {$$ = lst_to_matrix($2);}
+       | T_MATRIX_BEGIN matrix T_MATRIX_END    {$$ = lst_to_matrix(ex_to_lst($2));}
        ;
 
 exprseq        : exp                   {$$ = exprseq($1);}
@@ -441,10 +441,15 @@ static ex f_series(const exprseq &e)
        return e[0].series(e[1], ex_to_numeric(e[2]).to_int());
 }
 
-static ex f_sqrfree(const exprseq &e)
+static ex f_sqrfree1(const exprseq &e)
+{
+       return sqrfree(e[0]);
+}
+
+static ex f_sqrfree2(const exprseq &e)
 {
-       CHECK_ARG(1, symbol, sqrfree);
-       return sqrfree(e[0], ex_to_symbol(e[1]));
+       CHECK_ARG(1, lst, sqrfree);
+       return sqrfree(e[0], ex_to_lst(e[1]));
 }
 
 static ex f_subs3(const exprseq &e)
@@ -532,7 +537,8 @@ static const fcn_init builtin_fcns[] = {
        {"quo", fcn_desc(f_quo, 3)},
        {"rem", fcn_desc(f_rem, 3)},
        {"series", fcn_desc(f_series, 3)},
-       {"sqrfree", fcn_desc(f_sqrfree, 2)},
+       {"sqrfree", fcn_desc(f_sqrfree1, 1)},
+       {"sqrfree", fcn_desc(f_sqrfree2, 2)},
        {"sqrt", fcn_desc(f_sqrt, 1)},
        {"subs", fcn_desc(f_subs2, 2)},
        {"subs", fcn_desc(f_subs3, 3)},
@@ -565,11 +571,7 @@ static ex f_ginac_function(const exprseq &es, int serial)
 }
 
 // All registered GiNaC functions
-#ifndef NO_NAMESPACE_GINAC
 void GiNaC::ginsh_get_ginac_functions(void)
-#else // ndef NO_NAMESPACE_GINAC
-void ginsh_get_ginac_functions(void)
-#endif // ndef NO_NAMESPACE_GINAC
 {
        vector<function_options>::const_iterator i = function::registered_functions().begin(), end = function::registered_functions().end();
        unsigned serial = 0;
@@ -587,7 +589,7 @@ void ginsh_get_ginac_functions(void)
 
 static fcn_tab::const_iterator find_function(const ex &sym, int req_params)
 {
-       const string &name = ex_to_symbol(sym).getname();
+       const string &name = ex_to_symbol(sym).get_name();
        typedef fcn_tab::const_iterator I;
        pair<I, I> b = fcns.equal_range(name);
        if (b.first == b.second)
@@ -699,11 +701,13 @@ static char **fcn_completion(char *text, int start, int end)
                // For shell commands, revert back to filename completion
                rl_completion_append_character = orig_completion_append_character;
                rl_basic_word_break_characters = orig_basic_word_break_characters;
+               rl_completer_word_break_characters = rl_basic_word_break_characters;
                return completion_matches(text, (CPFunction *)filename_completion_function);
        } else {
                // Otherwise, complete function names
                rl_completion_append_character = '(';
                rl_basic_word_break_characters = " \t\n\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~";
+               rl_completer_word_break_characters = rl_basic_word_break_characters;
                return completion_matches(text, (CPFunction *)fcn_generator);
        }
 }
@@ -711,7 +715,7 @@ static char **fcn_completion(char *text, int start, int end)
 void greeting(void)
 {
     cout << "ginsh - GiNaC Interactive Shell (" << PACKAGE << " V" << VERSION << ")" << endl;
-    cout << "  __,  _______  Copyright (C) 1999-2000 Johannes Gutenberg University Mainz,\n"
+    cout << "  __,  _______  Copyright (C) 1999-2001 Johannes Gutenberg University Mainz,\n"
          << " (__) *       | Germany.  This is free software with ABSOLUTELY NO WARRANTY.\n"
          << "  ._) i N a C | You are welcome to redistribute it under certain conditions.\n"
          << "<-------------' For details type `warranty;'.\n" << endl;