]> www.ginac.de Git - ginac.git/commitdiff
Fixed the parser such that it can read in user defined classes again.
authorJens Vollinga <jensv@balin.nikhef.nl>
Fri, 31 Jul 2009 10:48:58 +0000 (12:48 +0200)
committerAlexei Sheplyakov <Alexei.Sheplyakov@gmail.com>
Thu, 9 Dec 2010 18:46:11 +0000 (20:46 +0200)
Fixed default reader to parse also pow, sqrt and power.

ginac/function.pl
ginac/parser/builtin_fcns.def
ginac/parser/default_reader.tpl
ginac/parser/parser.cpp

index 495432bbff3cd4e8d8fc8b56550a22f474f1a149..1ca923d462fb9556442434612e0c9f9c3d6bee3e 100644 (file)
@@ -843,6 +843,9 @@ function::function(unsigned ser, const exprseq & es) : exprseq(es), serial(ser)
 function::function(unsigned ser, const exvector & v, bool discardable) 
   : exprseq(v,discardable), serial(ser)
 {
+       if ( ser >= registered_functions().size() ) {
+               throw std::runtime_error("function does not exist");
+       }
 }
 
 function::function(unsigned ser, std::auto_ptr<exvector> vp) 
index 897b1f72096cf2f0168482cf481367743af20d0b..96cd0a24a26c23c2974a49676439603109427abd 100644 (file)
@@ -1,81 +1,5 @@
 Autogen definitions ginacfcns;
 
-function = { name = "log"; };
-function = { name = "exp"; };
-function = { name = "sin"; };
-function = { name = "cos"; };
-function = { name = "tan"; };
-function = { name = "asin"; };
-function = { name = "acos"; };
-function = { name = "atan"; };
-
-function = { name = "sinh"; };
-function = { name = "cosh"; };
-function = { name = "tanh"; };
-function = { name = "asinh"; };
-function = { name = "acosh"; };
-function = { name = "atanh"; };
-
-function = { 
-       name = "atan2";
-       args = 2;
-};
-
-function = { 
-       name = "Li2";
-       comment = "Dilogarithm";
-};
-
-function = {
-       name = "Li3";
-       comment = "Trilogarithm";
-};
-
-function = {
-       name = "zetaderiv";
-       comment = "Derivatives of Riemann's Zeta-function";
-       args = 2;
-};
-
-function = {
-       name = "Li";
-       args = 2;
-       comment = "Polylogarithm and multiple polylogarithm";
-};
-
-function = {
-       name =  "S";
-       args = 3;
-       comment = "Nielsen's generalized polylogarithm";
-};
-
-function = {
-       name =  "H";
-       args = 2;
-       comment = "Harmonic polylogarithm";
-};
-
-function = { name = "lgamma"; };
-function = { name = "tgamma"; };
-
-function = {
-       name = "beta";
-       args = 2;
-       comment = "Beta-function";
-};
-
-function = { name = "factorial"; };
-
-function = {
-       name = "binomial";
-       args = 2;
-};
-
-function = {
-       name = "Order";
-       comment = "Order term function (for truncated power series)";
-};
-
 /* Thease are not functions, but anyway ... */
 function = { name = "sqrt"; };
 
index 244074fa17fb731ff49e6f448ff8f905fd114911..5f83cfee30402a13cb0a8d0e355972b023310f1d 100644 (file)
@@ -37,6 +37,11 @@ const prototype_table& get_default_reader()
        static bool initialized = false;
        static prototype_table reader;
        if (!initialized) {
+               [+ FOR function +]
+               reader[make_pair("[+ (get "name") +]", [+ 
+                       (if (exist? "args") (get "args") "1")
+                       +])] = [+ (get "name") +]_reader;[+
+               ENDFOR +]
                try {
                        for ( unsigned ser=0; ; ++ser ) {
                                GiNaC::function f(ser);
index a3f3f0520c8c6bbff90330f76303af69361e1b05..32802316be4d60754bc8c5f908782edd3aba03ae 100644 (file)
@@ -66,8 +66,16 @@ ex parser::parse_identifier_expr()
                Parse_error_("no function \"" << name << "\" with " <<
                             args.size() << " arguments");
        }
-       ex ret = GiNaC::function(reinterpret_cast<unsigned>(reader->second), args);
-       return ret;
+       // dirty hack to distinguish between serial numbers of functions and real
+       // pointers.
+       ex ret;
+       try {
+               ret = GiNaC::function(reinterpret_cast<unsigned>(reader->second), args);
+       }
+       catch ( std::runtime_error ) {
+               ret = reader->second(args);
+       }
+    return ret;
 }
 
 /// paren_expr:  '(' expression ')'