[GiNaC-list] parse own function

Jens Vollinga jensv at nikhef.nl
Sun Jun 14 12:40:58 CEST 2009


Hi Jan,

what you see is a bug in GiNaC (or at least in the documentation because 
it doesn't describe a possible though ugly work-around), your code is fine.

A working version would be:

#include <iostream>
#include <ginac/ginac.h>

using namespace std;
using namespace GiNaC;

DECLARE_FUNCTION_3P(myfct)
REGISTER_FUNCTION(myfct,dummy())
ex myfct_reader(const exvector& ev)
{
     return myfct(ev[0], ev[1], ev[2]);
}

int main(int argc, char **argv)
{
     symbol x("x"),y("y");
     symtab table;
     table["x"] = x;
     table["y"] = y;
     prototype_table funcs = get_default_reader();
     funcs[make_pair("myfct", 3)] = myfct_reader;
     parser reader(table, false, funcs);
     string str = "myfct(x,y,2)";
     ex e = reader(str);
     cout  << e << endl;
     return 0;
}

Anyway, thanks for the "bug"-report. We'll try to fix it.

Regards,
Jens



Jan.M schrieb:
> hello,
> 
> i'm new to ginac and got some problems with parsing own functions:
> 
> #include <iostream>
> #include <ginac/ginac.h>
> 
> using namespace std;
> using namespace GiNaC;
> 
> DECLARE_FUNCTION_3P(myfct)
> REGISTER_FUNCTION(myfct,dummy())
> 
> 
> int main(int argc, char **argv){
>     symbol x("x"),y("y");
>     lst all;
> 
>     all = x,y;
> 
>     string str = "myfct(x,y,2)";
>     ex e(str, all);
>     cout  << e << endl;
> 
>     return 0;
> }
> 
> --->
> terminate called after throwing an instance of 'GiNaC::parse_error'
>   what():  GiNaC: parse error at line 0, column 0: no function "myfct" with
> 3 arguments
> [GiNaC::ex GiNaC::parser::parse_identifier_expr()(parser/parser.cpp:66)]
> 
> have i forgot something?  thanks in advance.
> 
> jan
> 



More information about the GiNaC-list mailing list