X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Finput_lexer.ll;h=4a5a65015e31ac983b64a92a18b1e8fb7457f694;hp=6396248d1fe23eb94233d8650aa50379312e14c0;hb=3229ec7c42ffc173f94f1c3bffbc30308c93e571;hpb=0025975e46fffba62c7b2b72f869b0bb1fe47e09 diff --git a/ginac/input_lexer.ll b/ginac/input_lexer.ll index 6396248d..4a5a6501 100644 --- a/ginac/input_lexer.ll +++ b/ginac/input_lexer.ll @@ -39,6 +39,7 @@ #include "numeric.h" #include "symbol.h" #include "lst.h" +#include "idx.h" using namespace GiNaC; namespace GiNaC { @@ -47,7 +48,7 @@ namespace GiNaC { } // namespace GiNaC -// Table of all used symbols +// Table of all used symbols/indices struct sym_def { sym_def() : predefined(false) {} sym_def(const ex &s, bool predef) : sym(s), predefined(predef) {} @@ -166,22 +167,34 @@ void set_lexer_string(const std::string &s) curr_pos = 0; } -// Set the list of predefined symbols +// Get name of symbol/index +std::string get_symbol_name(const ex & s) +{ + if (is_a(s)) + return ex_to(s).get_name(); + else if (is_a(s) && is_a(s.op(0))) + return ex_to(s.op(0)).get_name(); + else + throw (std::runtime_error("get_symbol_name(): unexpected expression type")); +} + +// Set the list of predefined symbols/indices void set_lexer_symbols(ex l) { syms.clear(); if (!is_exactly_a(l)) return; for (unsigned i=0; i(l.op(i))) - syms[ex_to(l.op(i)).get_name()] = sym_def(l.op(i), true); + const ex &o = l.op(i); + if (is_a(o) || (is_a(o) && is_a(o.op(0)))) + syms[get_symbol_name(o)] = sym_def(o, true); } } -// Check whether symbol was predefined +// Check whether symbol/index was predefined bool is_lexer_symbol_predefined(const ex &s) { - sym_tab::const_iterator i = syms.find(ex_to(s).get_name()); + sym_tab::const_iterator i = syms.find(get_symbol_name(s)); if (i == syms.end()) return false; else