Hi there, implementing interactive GiNaC programs is made extremely painful by the fact that GiNaC's parser accepts too much. This claim can be checked with the attached program derived from an example in the tutorial. Basically, stuff at the end of the string sometimes is accepted even if nonsensical. Moreover, once a well-formed string has been parsed, things tend to be accepted anyway. $ a.out Enter an expression containing 'x': x.13 put what you want here The derivative of x with respect to x is 1. $ a.out Enter an expression containing 'x': x. The derivative of 0 with respect to x is 0. Enter an expression containing 'x': x.13 put what you want here The derivative of x with respect to x is 1. Again: $ a.out Enter an expression containing 'x': 0 The derivative of 0 with respect to x is 0. Enter an expression containing 'x': log(|x|) The derivative of 0 with respect to x is 0. Enter an expression containing 'x': log(|x|+put anything here) The derivative of 0 with respect to x is 0. All the best Roberto -- Prof. Roberto Bagnara Computer Science Group Department of Mathematics, University of Parma, Italy http://www.cs.unipr.it/~bagnara/ mailto:bagnara@cs.unipr.it #include <iostream> #include <string> #include <stdexcept> #include <ginac/ginac.h> using namespace std; using namespace GiNaC; int main() { while (true) { symbol x("x"); string s; cout << "Enter an expression containing 'x': "; getline(cin, s); if (!cin) return 0; try { ex e(s, lst(x)); cout << "The derivative of " << e << " with respect to x is "; cout << e.diff(x) << ".\n"; } catch (exception &p) { cerr << p.what() << endl; } } }
Hi! On Sun, Oct 20, 2002 at 09:37:58AM +0200, Roberto Bagnara wrote:
Basically, stuff at the end of the string sometimes is accepted even if nonsensical.
This should work better now. Bye, Christian -- / Coding on PowerPC and proud of it \/ http://www.uni-mainz.de/~bauec002/
participants (2)
-
Christian Bauer
-
Roberto Bagnara