From: Jens Vollinga Date: Fri, 31 Jul 2009 10:48:58 +0000 (+0200) Subject: Fixed the parser such that it can read in user defined classes again. X-Git-Tag: release_1-5-4~19 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=8bf0597dde55e4c94a2ff39f1d8130902e3d7a9b Fixed the parser such that it can read in user defined classes again. Fixed default reader to parse also pow, sqrt and power. --- diff --git a/ginac/function.pl b/ginac/function.pl index 708d00e8..b8f7ea7d 100644 --- a/ginac/function.pl +++ b/ginac/function.pl @@ -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 vp) diff --git a/ginac/parser/builtin_fcns.def b/ginac/parser/builtin_fcns.def index 897b1f72..96cd0a24 100644 --- a/ginac/parser/builtin_fcns.def +++ b/ginac/parser/builtin_fcns.def @@ -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"; }; diff --git a/ginac/parser/default_reader.tpl b/ginac/parser/default_reader.tpl index 244074fa..5f83cfee 100644 --- a/ginac/parser/default_reader.tpl +++ b/ginac/parser/default_reader.tpl @@ -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); diff --git a/ginac/parser/parser.cpp b/ginac/parser/parser.cpp index a46017d3..d91b7e86 100644 --- a/ginac/parser/parser.cpp +++ b/ginac/parser/parser.cpp @@ -66,8 +66,16 @@ ex parser::parse_identifier_expr() Parse_error_("no function \"" << name << "\" with " << args.size() << " arguments"); } - ex ret = GiNaC::function(reinterpret_cast(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(reader->second), args); + } + catch ( std::runtime_error ) { + ret = reader->second(args); + } + return ret; } /// paren_expr: '(' expression ')'