1 /** @file parse_context.h
3 * Interface to parser context. */
6 * GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #ifndef GINAC_PARSE_CONTEXT_H
24 #define GINAC_PARSE_CONTEXT_H
29 #include <cstddef> // for size_t
37 * Establishes correspondence between the strings and expressions.
38 * The parser will create missing symbols (if not instructed otherwise,
39 * in which case it fails if the expression contains unknown symbols).
41 typedef std::map<std::string, ex> symtab;
44 * Find the symbol (or abbreviation) with the @a name in the symbol table @a syms.
46 * If symbol is missing and @a strict = false, insert it, otherwise
50 find_or_insert_symbol(const std::string& name, symtab& syms,
54 * Function (or class ctor) prototype
55 * .first is the name of function(or ctor),
56 * .second is the number of arguments (each of type ex)
58 typedef std::pair<std::string, std::size_t> prototype;
61 * A (C++) function for reading functions and classes from the stream.
63 * The parser uses (an associative array of) such functions to construct
64 * (GiNaC) classes and functions from a sequence of characters.
66 typedef ex (*reader_func)(const exvector& args);
71 * If parser sees an expression which looks like a function call (e.g.
72 * foo(x+y, z^2, t)), it looks up such a table to find out which
73 * function (or class) corresponds to the given name and has the given
74 * number of the arguments.
78 * 1. The function don't have to return a (GiNaC) function or class, it
79 * can return any expression.
80 * 2. Overloaded functions/ctors are paritally supported, i.e. there might
81 * be several functions with the same name, but they should take different
82 * number of arguments.
83 * 3. User can extend the parser via custom prototype tables. It's possible
84 * to read user defined classes, create abbreviations, etc.
86 * NOTE: due to a hack that allows user defined functions to be parsed, the map
87 * value of type reader_func is internally treated as an unsigned and not as a
88 * function pointer!! The unsigned has to correspond to the serial number of
89 * the defined GiNaC function.
91 typedef std::map<prototype, reader_func> prototype_table;
94 * Default prototype table.
96 * It supports all defined GiNaC functions and "pow", "sqrt", and "power".
98 extern const prototype_table& get_default_reader();
100 * Builtin prototype table.
102 * It supports only the builtin GiNaC functions and "pow", "sqrt", and "power".
104 extern const prototype_table& get_builtin_reader();
108 #endif // GINAC_PARSE_CONTEXT_H