]> www.ginac.de Git - ginac.git/blobdiff - ginac/input_lexer.ll
- Remved obsolete remainders of preprocessor symbol NO_NAMESPACE_GINAC.
[ginac.git] / ginac / input_lexer.ll
index eebdae4ae418030b4bbee9d736bc6e2298cc1368..6c22ec08dbca76c800fea1654292a3c23c4ae9b0 100644 (file)
@@ -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-2001 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
 #include "numeric.h"
 #include "symbol.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
-typedef map<string, ex> 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 std::map<std::string, sym_def> sym_tab;
 static sym_tab syms;
 
 // lex input function
@@ -59,9 +73,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 +88,12 @@ AN  [0-9a-zA-Z_]
 [ \t]+                 /* skip whitespace */
 
                        /* special values */
-Pi                     yylval = Pi; return T_LITERAL;
-gamma                  yylval = gamma; 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 +107,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;
                        }
 
@@ -119,7 +136,7 @@ Digits                      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;
@@ -143,12 +160,10 @@ 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;
@@ -162,10 +177,18 @@ void set_lexer_symbols(ex l)
                return;
        for (int i=0; i<l.nops(); i++) {
                if (is_ex_exactly_of_type(l.op(i), symbol))
-                       syms[ex_to_symbol(l.op(i)).getname()] = l.op(i);
+                       syms[ex_to_symbol(l.op(i)).get_name()] = sym_def(l.op(i), true);
        }
 }
 
-#ifndef NO_NAMESPACE_GINAC
+// Check whether symbol was predefined
+bool is_lexer_symbol_predefined(const ex &s)
+{
+       sym_tab::const_iterator i = syms.find(ex_to_symbol(s).get_name());
+       if (i == syms.end())
+               return false;
+       else
+               return (*i).second.predefined;
+}
+
 } // namespace GiNaC
-#endif // ndef NO_NAMESPACE_GINAC