1 /// @file parser_compat.cpp Parser interface compatible with the old
2 /// (bison/flex based) parser.
12 static symtab make_symtab(const ex& l);
14 ptr<basic> ex::construct_from_string_and_lst(const std::string &s, const ex &l)
16 static const bool strict = true;
17 symtab syms = make_symtab(l);
18 parser reader(syms, strict);
19 ex parsed_ex = reader(s);
23 static std::string get_symbol_name(const ex & s);
25 static symtab make_symtab(const ex& l)
28 if (is_exactly_a<lst>(l)) {
29 for (std::size_t i = 0; i < l.nops(); i++) {
30 const ex &o = l.op(i);
31 if (is_a<symbol>(o) || (is_a<idx>(o) && is_a<symbol>(o.op(0))))
32 syms[get_symbol_name(o)] = o;
38 static std::string get_symbol_name(const ex & s)
41 return ex_to<symbol>(s).get_name();
42 else if (is_a<idx>(s) && is_a<symbol>(s.op(0)))
43 return ex_to<symbol>(s.op(0)).get_name();
45 throw (std::invalid_argument("get_symbol_name(): unexpected expression type"));