]> www.ginac.de Git - ginac.git/blobdiff - ginsh/ginsh_parser.yy
- Derivatives are now assembled in a slightly different manner (i.e. they
[ginac.git] / ginsh / ginsh_parser.yy
index 8538ad0bcf192b2d511be73f485188e703900d81..d792a242f9c498a788fbf1e9ecf5523945e4a6e5 100644 (file)
@@ -87,7 +87,7 @@ static void print_help_topics(void);
 %token T_NUMBER T_SYMBOL T_LITERAL T_DIGITS T_QUOTE T_QUOTE2 T_QUOTE3
 %token T_EQUAL T_NOTEQ T_LESSEQ T_GREATEREQ T_MATRIX_BEGIN T_MATRIX_END
 
-%token T_QUIT T_WARRANTY T_PRINT T_READ T_WRITE T_TIME T_XYZZY T_INVENTORY T_LOOK T_SCORE
+%token T_QUIT T_WARRANTY T_PRINT T_IPRINT T_TIME T_XYZZY T_INVENTORY T_LOOK T_SCORE
 
 /* Operator precedence and associativity */
 %right '='
@@ -137,7 +137,22 @@ line       : ';'
                        YYERROR;
                }
        }
+       | T_IPRINT '(' exp ')' ';' {
+               try {
+                       ex e = $3;
+                       if (!e.info(info_flags::integer))
+                               throw (std::invalid_argument("argument to iprint() must be an integer"));
+                       long i = ex_to_numeric(e).to_long();
+                       cout << i << endl;
+                       cout << "#o" << oct << 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_TIME            {print_help("time");}
        | '?' '?'               {print_help_topics();}
        | T_QUIT                {YYACCEPT;}
        | T_WARRANTY {
@@ -161,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;}
        ;
@@ -173,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) {
@@ -270,7 +285,7 @@ static ex f_pow(const exprseq &e) {return pow(e[0], e[1]);}
 static ex f_sqrt(const exprseq &e) {return sqrt(e[0]);}
 static ex f_subs2(const exprseq &e) {return e[0].subs(e[1]);}
 
-#define CHECK_ARG(num, type, fcn) if (!is_ex_of_type(e[num], type)) throw(std::invalid_argument("argument " #num " to " #fcn " must be a " #type))
+#define CHECK_ARG(num, type, fcn) if (!is_ex_of_type(e[num], type)) throw(std::invalid_argument("argument " #num " to " #fcn "() must be a " #type))
 
 static ex f_charpoly(const exprseq &e)
 {