Faster, better (recursive descent) expression parser.
[ginac.git] / ginac / parser / parse_context.cpp
1 #include "parse_context.hpp"
2 #include <sstream>
3 #include <stdexcept>
4 namespace GiNaC
5 {
6
7 const 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                 return p->second.first;
13
14         if (strict)
15                 throw std::invalid_argument(
16                                 std::string("find_or_insert_symbol: symbol \"") 
17                                 + name + "\" not found");
18
19         // false means this symbol was created by parser 
20         const std::pair<symbol, bool> tmp = std::make_pair(symbol(name), false);
21
22         symtab::iterator i = syms.insert(symtab::value_type(name, tmp)).first;
23         return i->second.first;
24 }
25
26 }
27