From e2a0d29ca8e926c51ea90fce65336fd4350c6794 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (laptop)" <j.wuttke@fz-juelich.de> Date: Sun, 30 Sep 2012 12:26:24 +0200 Subject: [PATCH] user_xaxparse now returns PTree; check non-dependence on dummy --- pub/src/calc.cpp | 6 +++--- pub/src/curve.cpp | 7 +++---- pub/src/manip.cpp | 11 +++++------ pub/src/opr.cpp | 20 ++++++++++++-------- pub/src/plot.cpp | 5 +++-- pub/src/xax_lex.h | 2 +- pub/src/xax_lex.lpp | 10 +++++++--- test/test1-fit.inp | 9 +++++---- 8 files changed, 39 insertions(+), 31 deletions(-) diff --git a/pub/src/calc.cpp b/pub/src/calc.cpp index 7bf2d435..07cf42ba 100644 --- a/pub/src/calc.cpp +++ b/pub/src/calc.cpp @@ -26,10 +26,10 @@ void NCalc::Calculator( string s ) { - PTree T; + PTree T = user_xaxparse( s.c_str() ); + if( T->has_dummy() ) + throw "dummy argument t not allowed outside curve definitions"; double ret, dret; - - user_xaxparse( s.c_str(), &T ); NOlm::IterateO fiter; if( fiter.size()==0 || !T->k_dependent() ) { T->tree_point_val( &ret, &dret ); diff --git a/pub/src/curve.cpp b/pub/src/curve.cpp index ad3c93a7..4879bde2 100644 --- a/pub/src/curve.cpp +++ b/pub/src/curve.cpp @@ -85,7 +85,7 @@ void COlc::parseFunction( const string& _expr ) { evaMode = COlc::_EXPR; expr = _expr; - user_xaxparse( expr.c_str(), &T ); + T = user_xaxparse( expr.c_str() ); if( !T->has_dummy() ) cerr << "WARNING: curve has no formal argument t\n"; } @@ -365,8 +365,7 @@ void NCurveFile::ChangeRange() fc->range_T = PTree(); continue; } - PTree T; - user_xaxparse( expr.c_str(), &T ); + PTree T = user_xaxparse( expr.c_str() ); fc->range_T = T; } } @@ -523,7 +522,7 @@ void NCurveFile::SetFileReference( const string& which ) else throw "BUG: unexpected which="+which; if (expr!="") - user_xaxparse( expr.c_str(), &T ); + T = user_xaxparse( expr.c_str() ); } POlc fc; diff --git a/pub/src/manip.cpp b/pub/src/manip.cpp index df468538..7336d623 100644 --- a/pub/src/manip.cpp +++ b/pub/src/manip.cpp @@ -269,8 +269,9 @@ void NManip::PtsSort() string expr = sask("Sort points according to"); if (expr=="") return; - PTree T; - user_xaxparse( expr.c_str(), &T ); + PTree T = user_xaxparse( expr.c_str() ); + if( T->has_dummy() ) + throw "dummy argument t not allowed when operating on data"; NOlm::IterateD fiter; POld fin; @@ -360,8 +361,7 @@ void NManip::PtsSymmetrize() static string expr = "0"; expr = sask( "Assume symmetry with mirror positioned at", expr ); if ( expr=="" ) return; - PTree T; - user_xaxparse( expr.c_str(), &T ); + PTree T = user_xaxparse( expr.c_str() ); NOlm::IterateD fiter; POld fin; @@ -737,8 +737,7 @@ void NManip::ScaSortByExpr() string expr = sask("Sort spectra according to"); if (expr=="") return; - PTree T; - user_xaxparse( expr.c_str(), &T ); + PTree T = user_xaxparse( expr.c_str() ); NOlm::IterateO fiter; POlo fin; diff --git a/pub/src/opr.cpp b/pub/src/opr.cpp index 12c1364f..864ff254 100644 --- a/pub/src/opr.cpp +++ b/pub/src/opr.cpp @@ -40,8 +40,9 @@ void NOperate::Show( const string& subcmd ) static string expr; expr = sask( "Show if", expr); if (expr=="") expr = "1"; - PTree T; - user_xaxparse( expr.c_str(), &T ); + PTree T = user_xaxparse( expr.c_str() ); + if( T->has_dummy() ) + throw "dummy argument t not allowed when operating on data"; NOlm::IterateD fiter; POld fin; @@ -102,8 +103,9 @@ void NOperate::Select( bool sel_del ) static string expr; expr = sask((sel_del ? "Delete" : "Retain"), expr); if (expr=="") return; - PTree T; - user_xaxparse( expr.c_str(), &T ); + PTree T = user_xaxparse( expr.c_str() ); + if( T->has_dummy() ) + throw "dummy argument t not allowed when operating on data"; NOlm::IterateO fiter; POlo fin; @@ -157,8 +159,9 @@ void NOperate::Pointwise( string llabel ) string expr = sask("Expression ?"); if (expr=="") return; - PTree T; - user_xaxparse( expr.c_str(), &T ); + PTree T = user_xaxparse( expr.c_str() ); + if( T->has_dummy() ) + throw "dummy argument t not allowed when operating on data"; NOlm::IterateO fiter; POlo fin; @@ -267,8 +270,9 @@ void NOperate::Integral(void) string expr = sask( "Functional ?" ); if ( expr=="" ) return; - PTree T; - user_xaxparse( expr.c_str(), &T ); + PTree T = user_xaxparse( expr.c_str() ); + if( T->has_dummy() ) + throw "dummy argument t not allowed when operating on data"; NOlm::IterateO fiter; POlo fin; diff --git a/pub/src/plot.cpp b/pub/src/plot.cpp index 2f9729fc..2a754971 100644 --- a/pub/src/plot.cpp +++ b/pub/src/plot.cpp @@ -232,8 +232,9 @@ void NPlot::Plot( class CPlot *plot, bool add ) yo.push_back( yp[i] ); } if ( xo.size()==0 ){ - cout << "curve k="<<strg(k)<<", j="<<strg(j)<<" is empty\n"; - return; + cout << "curve k="<<strg(k)<<", j="<<strg(j)<< + " has no points in plot window\n"; + continue; } plot->addSpec( true, true, cstyle++, xo, yo, novec, f->V[j]->z, f->xco.str(), f->yco.str(), diff --git a/pub/src/xax_lex.h b/pub/src/xax_lex.h index b858b40b..1477d813 100644 --- a/pub/src/xax_lex.h +++ b/pub/src/xax_lex.h @@ -1 +1 @@ -int user_xaxparse(const char *lin, boost::shared_ptr<class CTree> *T); +boost::shared_ptr<class CTree> user_xaxparse(const char *lin); diff --git a/pub/src/xax_lex.lpp b/pub/src/xax_lex.lpp index 070add07..d615e487 100644 --- a/pub/src/xax_lex.lpp +++ b/pub/src/xax_lex.lpp @@ -15,6 +15,7 @@ using namespace std; #include <math.h> #include <string> #include <vector> +#include "mystd.h" #include "func.h" #include "reg.h" #include "var.h" @@ -132,11 +133,14 @@ e { int xaxparse( void* ); -int user_xaxparse( const char *lin, boost::shared_ptr<class CTree> *T ) +boost::shared_ptr<class CTree> user_xaxparse( const char *lin ) { + boost::shared_ptr<class CTree> T; int err; xax_scan_string(lin); - err=xaxparse((void*) T); + err=xaxparse((void*) &T); xax_delete_buffer(YY_CURRENT_BUFFER); - return err; + if( err ) + throw "lexer/parser error " + strg(err); + return T; } diff --git a/test/test1-fit.inp b/test/test1-fit.inp index 928f3d20..eb69a723 100644 --- a/test/test1-fit.inp +++ b/test/test1-fit.inp @@ -1,10 +1,11 @@ fl dat-res fl dat-qel -1 mpd= 1 -1 cc p0+p1*resol+p2*conv(cauchy(t,p3)) -1 cc p0+p1*resol+p2*pi/2*pconv(atan(t/p3)) +#1 cc p0+p1*resol+p2*conv(cauchy(t,p3)) +#1 cc p0+p1*resol+p2*pi/2*pconv(atan(t/p3)) +1 cc p0*conv(kwwc(t,p1,.6)) +1 cc p0*pconv(kwwp(t,p1,.6)) 2,3 cv 0 -2,3 cfs +2,3 cf g2 0-3 p 1 2,3 cp -- GitLab