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=5a3bfbdb22e1f2d62f98dd868d17270ffc8d35c6;hb=3229ec7c42ffc173f94f1c3bffbc30308c93e571;hpb=f2fae86fdf68eaf32111ae4ef9c1171c0e5c46a9 diff --git a/ginac/input_lexer.ll b/ginac/input_lexer.ll index 5a3bfbdb..4a5a6501 100644 --- a/ginac/input_lexer.ll +++ b/ginac/input_lexer.ll @@ -4,7 +4,7 @@ * This file must be processed with flex. */ /* - * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2002 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -38,19 +38,17 @@ #include "fail.h" #include "numeric.h" #include "symbol.h" +#include "lst.h" +#include "idx.h" -#ifndef NO_NAMESPACE_GINAC using namespace GiNaC; namespace GiNaC { -#endif // ndef NO_NAMESPACE_GINAC #include "input_parser.h" -#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_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) {} @@ -69,7 +67,7 @@ struct sym_def { ex sym; bool predefined; // true = user supplied symbol, false = lexer generated symbol }; -typedef map sym_tab; +typedef std::map sym_tab; static sym_tab syms; // lex input function @@ -105,10 +103,6 @@ Digits ginac_yylval = (long)Digits; return T_DIGITS; "<=" return T_LESSEQ; ">=" return T_GREATEREQ; - /* matrix delimiters */ -\[\[ return T_MATRIX_BEGIN; -\]\] return T_MATRIX_END; - /* numbers */ {D}+ | "#"{D}+"R"{AN}+ | @@ -125,7 +119,7 @@ Digits ginac_yylval = (long)Digits; return T_DIGITS; if (i == syms.end()) { syms[yytext] = sym_def(ginac_yylval = *(new symbol(yytext)), false); } else - ginac_yylval = i->second.sym; + ginac_yylval = (*i).second.sym; return T_SYMBOL; } @@ -140,7 +134,7 @@ Digits ginac_yylval = (long)Digits; return T_DIGITS; */ // The string from which we will read -static string lexer_string; +static std::string lexer_string; // The current position within the string static int curr_pos = 0; @@ -164,39 +158,47 @@ int ginac_yywrap() return 1; } -#ifndef NO_NAMESPACE_GINAC namespace GiNaC { -#endif // ndef NO_NAMESPACE_GINAC // Set the input string -void set_lexer_string(const string &s) +void set_lexer_string(const std::string &s) { lexer_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_ex_exactly_of_type(l, lst)) + if (!is_exactly_a(l)) return; - for (int i=0; i(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_symbol(s).getname()); + sym_tab::const_iterator i = syms.find(get_symbol_name(s)); if (i == syms.end()) return false; else - return i->second.predefined; + return (*i).second.predefined; } -#ifndef NO_NAMESPACE_GINAC } // namespace GiNaC -#endif // ndef NO_NAMESPACE_GINAC