X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fparser%2Fparse_context.h;h=60151fd37988af0538f6b000bd50285930ee8d7d;hp=07496d7e8e26f0ac13fe0484f42643a2118b0ccd;hb=9a4f392521083d28e1c238e7898ab1d2ac5b73cd;hpb=df823d53c56c762072f534c9f24479090162e33a diff --git a/ginac/parser/parse_context.h b/ginac/parser/parse_context.h index 07496d7e..60151fd3 100644 --- a/ginac/parser/parse_context.h +++ b/ginac/parser/parse_context.h @@ -3,7 +3,7 @@ * Interface to parser context. */ /* - * GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2011 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 @@ -72,18 +72,49 @@ typedef ex (*reader_func)(const exvector& args); * foo(x+y, z^2, t)), it looks up such a table to find out which * function (or class) corresponds to the given name and has the given * number of the arguments. + * + * N.B. + * + * 1. The function don't have to return a (GiNaC) function or class, it + * can return any expression. + * 2. Overloaded functions/ctors are paritally supported, i.e. there might + * be several functions with the same name, but they should take different + * number of arguments. + * 3. User can extend the parser via custom prototype tables. It's possible + * to read user defined classes, create abbreviations, etc. + * + * NOTE: due to a hack that allows user defined functions to be parsed, the map + * value of type reader_func is internally treated as an unsigned and not as a + * function pointer!! The unsigned has to correspond to the serial number of + * the defined GiNaC function. */ -typedef std::map prototype_table; +class PrototypeLess +{ +public: + bool operator()(const prototype& p1, const prototype& p2) const + { + int s = p1.first.compare(p2.first); + if (s == 0) { + if ((p1.second == 0) || (p2.second == 0)) return false; + return p1.second < p2.second; + } + return s < 0; + } +}; +typedef std::map prototype_table; /** - * Creates a default prototype table containing all defined GiNaC functions. + * Default prototype table. + * + * It supports all defined GiNaC functions and "pow", "sqrt", and "power". + */ +extern const prototype_table& get_default_reader(); +/** + * Builtin prototype table. * - * The data referenced by the return value is only created once when this - * function is called for the first time. This might cause problems in very - * rare stituations (i.e. if functions are added after this first call). In - * that case, a new initialization can be forced with an "true" argument. + * It supports only the builtin GiNaC functions and "pow", "sqrt", and "power". */ -extern const prototype_table& get_default_reader(bool force_init = false); +extern const prototype_table& get_builtin_reader(); } // namespace GiNaC