X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Finput_lexer.ll;h=d8bfd36282c8e4d011d95d87e4fab7e256d73af1;hp=6c22ec08dbca76c800fea1654292a3c23c4ae9b0;hb=8dc09f48182574d792a2ed7c37b66831d9267a6c;hpb=f5536efa098703ce4e857aa079db6d29d06f3ac6 diff --git a/ginac/input_lexer.ll b/ginac/input_lexer.ll index 6c22ec08..d8bfd362 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-2001 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2003 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,6 +38,8 @@ #include "fail.h" #include "numeric.h" #include "symbol.h" +#include "lst.h" +#include "idx.h" using namespace GiNaC; namespace GiNaC { @@ -46,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) {} @@ -85,7 +87,7 @@ AN [0-9a-zA-Z_] */ %% -[ \t]+ /* skip whitespace */ +[ \t\n]+ /* skip whitespace */ /* special values */ Pi ginac_yylval = Pi; return T_LITERAL; @@ -101,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,6 +123,9 @@ Digits ginac_yylval = (long)Digits; return T_DIGITS; return T_SYMBOL; } + /* end of input */ +<> return T_EOF; + /* everything else */ . return *yytext; @@ -169,22 +170,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_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).get_name()); + sym_tab::const_iterator i = syms.find(get_symbol_name(s)); if (i == syms.end()) return false; else