Aggiunti metodi parse_user_func e string
git-svn-id: svn://10.65.10.50/trunk@3447 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
607e672174
commit
38f03725d7
@ -194,10 +194,10 @@ TExpression::operator const char*()
|
||||
void TExpression::print_on(ostream& out) const
|
||||
{ out << _original; }
|
||||
|
||||
void TExpression::evaluate_user_func(const char * name, int nparms, TStack & stack, TTypeexp type) const
|
||||
void TExpression::evaluate_user_func(int index, int nparms, TStack & stack, TTypeexp type) const
|
||||
|
||||
{
|
||||
NFCHECK("Unknown function : %s ", name);
|
||||
CHECKD(FALSE, "Unknown function ", index);
|
||||
for ( int i = nparms ; i > 0; i--)
|
||||
stack.pop();
|
||||
stack.push(ZERO);
|
||||
@ -445,8 +445,9 @@ void TExpression::eval()
|
||||
case _userfunc:
|
||||
{
|
||||
const int nparms = (int) ((real &) evalstack.pop()).integer();
|
||||
const int index = atoi(instr.string());
|
||||
|
||||
evaluate_user_func(instr.string(), nparms, evalstack, type);
|
||||
evaluate_user_func(index, nparms, evalstack, type);
|
||||
}
|
||||
break;
|
||||
case _sqrt:
|
||||
@ -867,9 +868,19 @@ TCodesym TExpression::__factor(TCodesym startsym)
|
||||
if (sym == _rpar)
|
||||
{
|
||||
_code.add(_number, real(nparms));
|
||||
_code.add(startsym, val);
|
||||
_user_func_defined = TRUE;
|
||||
sym = __gettoken(TRUE);
|
||||
const int index = parse_user_func((const char *) val.string(), nparms);
|
||||
if (index < 0)
|
||||
{
|
||||
strcpy(_tok, (const char *) val.string());
|
||||
sym = _invalid;
|
||||
}
|
||||
else
|
||||
{
|
||||
val.set(format("%d", index));
|
||||
_code.add(startsym, val);
|
||||
_user_func_defined = TRUE;
|
||||
sym = __gettoken(TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -416,7 +416,8 @@ protected:
|
||||
protected: // TObject
|
||||
// @cmember Stampa l'espressione su <p out> (serve per implementare l'insertore)
|
||||
virtual void print_on(ostream& out) const ;
|
||||
virtual void evaluate_user_func(const char * name, int nparms, TStack & stack, TTypeexp type) const ;
|
||||
virtual void evaluate_user_func(int index, int nparms, TStack & stack, TTypeexp type) const;
|
||||
virtual int parse_user_func(const char * name, int nparms) const { return -1; }
|
||||
|
||||
// @access Public Member
|
||||
public:
|
||||
@ -458,6 +459,8 @@ public:
|
||||
// @cmember Setta l'espressione e la compila (ritorna il risultato della compilazione)
|
||||
bool set(const char* expression, TTypeexp type = _numexpr);
|
||||
const char* last_compiled_token() const;
|
||||
// @cmember Ritorna l'espressione originale
|
||||
const char * string() const { return _original; }
|
||||
|
||||
// @cmember Costruttore (assegna l'estressione e il suo tipo)
|
||||
TExpression(const char* expression, TTypeexp type = _numexpr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user