]> www.ginac.de Git - ginac.git/commitdiff
Parser: handle abbreviations as advertized in the manual.
authorAlexei Sheplyakov <alexei.sheplyakov@gmail.com>
Mon, 5 Jul 2010 07:15:20 +0000 (09:15 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Mon, 5 Jul 2010 07:15:20 +0000 (09:15 +0200)
The following example from the tutorial

GiNaC::symbol x, y;
GiNaC::symtab table;
table["x"] = x+log(y)+1;
GiNaC::parser reader(table);
GiNaC::ex e = reader("5*x3 - x2");

fails with the following exception:

terminate called after throwing an instance of 'std::invalid_argument'
what(): find_or_insert_symbol: name "x" does not correspond to a symbol

Remove silly checks from find_or_insert_symbol, and fix its return value
(should be ex, not symbol).

ginac/parser/parse_context.cpp
ginac/parser/parse_context.h

index 1b1d38f7979cc160de030c244887c11f05a9163e..88b0b30ec9b298cce1652e03318b3bd2ad2590aa 100644 (file)
 
 namespace GiNaC {
 
 
 namespace GiNaC {
 
-symbol
+ex
 find_or_insert_symbol(const std::string& name, symtab& syms, const bool strict)
 {
        symtab::const_iterator p = syms.find(name);
 find_or_insert_symbol(const std::string& name, symtab& syms, const bool strict)
 {
        symtab::const_iterator p = syms.find(name);
-       if (p != syms.end()) {
-               if (is_a<symbol>(p->second))
-                       return ex_to<symbol>(p->second);
-               else
-                       throw std::invalid_argument(
-                               std::string("find_or_insert_symbol: name \"")
-                               + name + "\" does not correspond to a symbol");
-       }
-
+       if (p != syms.end())
+               return p->second;
 
        if (strict)
                throw std::invalid_argument(
 
        if (strict)
                throw std::invalid_argument(
index b227c6654fb40d4e917e39e0067b859f5865ef60..07496d7e8e26f0ac13fe0484f42643a2118b0ccd 100644 (file)
@@ -41,12 +41,12 @@ namespace GiNaC {
 typedef std::map<std::string, ex> symtab;
 
 /**
 typedef std::map<std::string, ex> symtab;
 
 /**
- * Find the symbol with the @a name in the symbol table @a syms.
+ * Find the symbol (or abbreviation) with the @a name in the symbol table @a syms.
  *
  * If symbol is missing and @a strict = false, insert it, otherwise
  * throw an exception.
  */
  *
  * If symbol is missing and @a strict = false, insert it, otherwise
  * throw an exception.
  */
-extern symbol
+extern ex 
 find_or_insert_symbol(const std::string& name, symtab& syms,
                      const bool strict);
 
 find_or_insert_symbol(const std::string& name, symtab& syms,
                      const bool strict);