]> www.ginac.de Git - ginac.git/blobdiff - ginac/operators.cpp
- expressions can now be read from streams; the input expression can contain
[ginac.git] / ginac / operators.cpp
index 10a45165b2fdc058a6606201d36947d84326a758..6cf750cefa7005542175ee6d46f2178a18a34787 100644 (file)
 #include "numeric.h"
 #include "power.h"
 #include "relational.h"
+#include "input_lexer.h"
 #include "debugmsg.h"
 #include "utils.h"
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 namespace GiNaC {
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC
 
 // binary arithmetic operators ex with ex
 
@@ -335,11 +336,23 @@ ostream & operator<<(ostream & os, const ex & e)
     return os;
 }
 
+/** Input (parse) expression from stream. The input grammar is similar to the
+ *  GiNaC output format. If 'e' contains a list of symbols upon entry, these
+ *  symbols are used in the parsed expression in all places where symbols with
+ *  the same names appear. All other encountered symbols will be newly created. */
 istream & operator>>(istream & is, ex & e)
 {
-    throw(std::logic_error("input from streams not yet implemented"));
+       string s;
+       getline(is, s);
+       set_lexer_string(s);
+       set_lexer_symbols(e);
+       ginac_yyrestart(NULL);
+       if (yyparse())
+               throw (std::runtime_error(get_parser_error()));
+       else
+               e = parsed_ex;
 }
 
-#ifndef NO_GINAC_NAMESPACE
+#ifndef NO_NAMESPACE_GINAC
 } // namespace GiNaC
-#endif // ndef NO_GINAC_NAMESPACE
+#endif // ndef NO_NAMESPACE_GINAC