1 /** @file parser_compat.cpp
3 * Parser interface compatible with the old (bison/flex based) parser. */
6 * GiNaC Copyright (C) 1999-2015 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
33 static symtab make_symtab(const ex& l);
35 ptr<basic> ex::construct_from_string_and_lst(const std::string &s, const ex &l)
37 static const bool strict = true;
38 symtab syms = make_symtab(l);
39 parser reader(syms, strict);
40 ex parsed_ex = reader(s);
44 static std::string get_symbol_name(const ex & s);
46 static symtab make_symtab(const ex& l)
49 if (is_exactly_a<lst>(l)) {
50 for (std::size_t i = 0; i < l.nops(); i++) {
51 const ex &o = l.op(i);
52 if (is_a<symbol>(o) || (is_a<idx>(o) && is_a<symbol>(o.op(0))))
53 syms[get_symbol_name(o)] = o;
59 static std::string get_symbol_name(const ex & s)
62 return ex_to<symbol>(s).get_name();
63 else if (is_a<idx>(s) && is_a<symbol>(s.op(0)))
64 return ex_to<symbol>(s.op(0)).get_name();
66 throw (std::invalid_argument("get_symbol_name(): unexpected expression type"));