X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Finput_lexer.ll;h=5a3bfbdb22e1f2d62f98dd868d17270ffc8d35c6;hb=a74473453218570d22f8932cc39ab48c7f0021ae;hp=e0e9b468a1186c37f3e98a01574d011b96c7f1be;hpb=a43a2fe7d9df31529647c66dcfb9cad544ffd369;p=ginac.git diff --git a/ginac/input_lexer.ll b/ginac/input_lexer.ll index e0e9b468..5a3bfbdb 100644 --- a/ginac/input_lexer.ll +++ b/ginac/input_lexer.ll @@ -51,7 +51,25 @@ namespace GiNaC { #endif // ndef NO_NAMESPACE_GINAC // Table of all used symbols -typedef map sym_tab; +struct sym_def { + sym_def() : predefined(false) {} + sym_def(const ex &s, bool predef) : sym(s), predefined(predef) {} + ~sym_def() {} + + sym_def(const sym_def &other) {sym = other.sym; predefined = other.predefined;} + const sym_def &operator=(const sym_def &other) + { + if (this != &other) { + sym = other.sym; + predefined = other.predefined; + } + return *this; + } + + ex sym; + bool predefined; // true = user supplied symbol, false = lexer generated symbol +}; +typedef map sym_tab; static sym_tab syms; // lex input function @@ -59,9 +77,6 @@ static int lexer_input(char *buf, int max_size); #define YY_INPUT(buf, result, max_size) (result = lexer_input(buf, max_size)) %} - /* The code output by flex doesn't work well with namespaces, so we're doing it this way */ -%option prefix="ginac_yy" - /* Abbreviations */ D [0-9] E [elEL][-+]?{D}+ @@ -77,12 +92,12 @@ AN [0-9a-zA-Z_] [ \t]+ /* skip whitespace */ /* special values */ -Pi yylval = Pi; return T_LITERAL; -Euler yylval = Euler; return T_LITERAL; -Catalan yylval = Catalan; return T_LITERAL; -FAIL yylval = *new fail(); return T_LITERAL; -I yylval = I; return T_NUMBER; -Digits yylval = (long)Digits; return T_DIGITS; +Pi ginac_yylval = Pi; return T_LITERAL; +Euler ginac_yylval = Euler; return T_LITERAL; +Catalan ginac_yylval = Catalan; return T_LITERAL; +FAIL ginac_yylval = *new fail(); return T_LITERAL; +I ginac_yylval = I; return T_NUMBER; +Digits ginac_yylval = (long)Digits; return T_DIGITS; /* comparison */ "==" return T_EQUAL; @@ -96,15 +111,21 @@ Digits yylval = (long)Digits; return T_DIGITS; /* numbers */ {D}+ | +"#"{D}+"R"{AN}+ | +"#b"([01])+ | +"#o"[0-7]+ | +"#x"[0-9a-fA-F]+ | {D}+"."{D}*({E})? | {D}*"."{D}+({E})? | -{D}+{E} yylval = numeric(yytext); return T_NUMBER; +{D}+{E} ginac_yylval = numeric(yytext); return T_NUMBER; /* symbols */ {A}{AN}* { - if (syms.find(yytext) == syms.end()) - syms[yytext] = *(new symbol(yytext)); - yylval = syms[yytext]; + sym_tab::const_iterator i = syms.find(yytext); + if (i == syms.end()) { + syms[yytext] = sym_def(ginac_yylval = *(new symbol(yytext)), false); + } else + ginac_yylval = i->second.sym; return T_SYMBOL; } @@ -162,10 +183,20 @@ void set_lexer_symbols(ex l) return; for (int i=0; isecond.predefined; +} + #ifndef NO_NAMESPACE_GINAC } // namespace GiNaC #endif // ndef NO_NAMESPACE_GINAC