]> www.ginac.de Git - ginac.git/blob - ginac/parser/parse_context.cpp
88b0b30ec9b298cce1652e03318b3bd2ad2590aa
[ginac.git] / ginac / parser / parse_context.cpp
1 /** @file parse_context.cpp
2  *
3  *  Implementation of the parser context. */
4
5 /*
6  *  GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "parse_context.h"
24
25 #include "function.h"
26
27 #include <sstream>
28 #include <stdexcept>
29
30 namespace GiNaC {
31
32 ex
33 find_or_insert_symbol(const std::string& name, symtab& syms, const bool strict)
34 {
35         symtab::const_iterator p = syms.find(name);
36         if (p != syms.end())
37                 return p->second;
38
39         if (strict)
40                 throw std::invalid_argument(
41                                 std::string("find_or_insert_symbol: symbol \"") 
42                                 + name + "\" not found");
43
44         const symbol sy(name);
45         syms[name] = sy;
46         return sy;
47 }
48
49 const prototype_table& get_default_reader(bool force_init)
50 {
51         using std::make_pair;
52         static bool initialized = false;
53         static prototype_table reader;
54         if ( !initialized || force_init ) {
55                 std::vector<function_options> flist = function::get_registered_functions();
56                 std::vector<function_options>::iterator i = flist.begin(), end = flist.end();
57                 for ( ; i != end; ++i ) {
58                         std::string name = i->get_name();
59                         unsigned narg = i->get_nparams();
60                         reader[make_pair(name, narg)] = function::find_function(name, narg);
61                 }
62                 initialized = true;
63         }
64         return reader;
65 }
66
67 } // namespace GiNaC