parser: map input strings onto arbitrary expressions (not only symbols).
[ginac.git] / ginac / parser / parse_context.cpp
1 #include "parse_context.hpp"
2 #include <sstream>
3 #include <stdexcept>
4 namespace GiNaC
5 {
6
7 symbol
8 find_or_insert_symbol(const std::string& name, symtab& syms, const bool strict)
9 {
10         symtab::const_iterator p = syms.find(name);
11         if (p != syms.end()) {
12                 if (is_a<symbol>(p->second))
13                         return ex_to<symbol>(p->second);
14                 else
15                         throw std::invalid_argument(
16                                 std::string("find_or_insert_symbol: name \"")
17                                 + name + "\" does not correspond to a symbol");
18         }
19
20
21         if (strict)
22                 throw std::invalid_argument(
23                                 std::string("find_or_insert_symbol: symbol \"") 
24                                 + name + "\" not found");
25
26         const symbol sy(name);
27         syms[name] = sy;
28         return sy;
29 }
30
31 }
32