macroprocessor: add length command. closes #436
parent
2464c330b3
commit
792b1b5924
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2012 Dynare Team
|
* Copyright (C) 2008-2013 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -80,7 +80,7 @@ class MacroDriver;
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%token DEFINE LINE FOR IN IF ELSE ENDIF ECHO_DIR ERROR IFDEF IFNDEF
|
%token DEFINE LINE FOR IN IF ELSE ENDIF ECHO_DIR ERROR IFDEF IFNDEF
|
||||||
%token LPAREN RPAREN LBRACKET RBRACKET EQUAL EOL
|
%token LPAREN RPAREN LBRACKET RBRACKET EQUAL EOL LENGTH
|
||||||
|
|
||||||
%token <int_val> INTEGER
|
%token <int_val> INTEGER
|
||||||
%token <string_val> NAME STRING
|
%token <string_val> NAME STRING
|
||||||
|
@ -145,6 +145,8 @@ expr : INTEGER
|
||||||
}
|
}
|
||||||
delete $1;
|
delete $1;
|
||||||
}
|
}
|
||||||
|
| LENGTH LPAREN array_expr RPAREN
|
||||||
|
{ TYPERR_CATCH($$ = $3->length(), @$); }
|
||||||
| LPAREN expr RPAREN
|
| LPAREN expr RPAREN
|
||||||
{ $$ = $2; }
|
{ $$ = $2; }
|
||||||
| expr PLUS expr
|
| expr PLUS expr
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2012 Dynare Team
|
* Copyright (C) 2008-2013 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -151,6 +151,7 @@ CONT \\\\
|
||||||
<STMT,EXPR>[*] { return token::TIMES; }
|
<STMT,EXPR>[*] { return token::TIMES; }
|
||||||
<STMT,EXPR>[/] { return token::DIVIDE; }
|
<STMT,EXPR>[/] { return token::DIVIDE; }
|
||||||
<STMT,EXPR>in { return token::IN; }
|
<STMT,EXPR>in { return token::IN; }
|
||||||
|
<STMT,EXPR>length { return token::LENGTH; }
|
||||||
|
|
||||||
<STMT,EXPR>\"[^\"]*\" {
|
<STMT,EXPR>\"[^\"]*\" {
|
||||||
yylval->string_val = new string(yytext + 1);
|
yylval->string_val = new string(yytext + 1);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2011 Dynare Team
|
* Copyright (C) 2008-2013 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -106,6 +106,12 @@ MacroValue::operator[](const MacroValue &mv) const throw (TypeError, OutOfBounds
|
||||||
throw TypeError("Operator [] does not exist for this type");
|
throw TypeError("Operator [] does not exist for this type");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MacroValue *
|
||||||
|
MacroValue::length() const throw (TypeError)
|
||||||
|
{
|
||||||
|
throw TypeError("Length not supported for this type");
|
||||||
|
}
|
||||||
|
|
||||||
const MacroValue *
|
const MacroValue *
|
||||||
MacroValue::append(const MacroValue *mv) const throw (TypeError)
|
MacroValue::append(const MacroValue *mv) const throw (TypeError)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2010 Dynare Team
|
* Copyright (C) 2008-2013 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -92,6 +92,8 @@ public:
|
||||||
virtual string toString() const = 0;
|
virtual string toString() const = 0;
|
||||||
//! Converts value to array form
|
//! Converts value to array form
|
||||||
virtual const MacroValue *toArray() const = 0;
|
virtual const MacroValue *toArray() const = 0;
|
||||||
|
//! Gets length
|
||||||
|
virtual const MacroValue *length() const throw (TypeError);
|
||||||
//! Appends value at the end of an array
|
//! Appends value at the end of an array
|
||||||
/*! The argument must be an array. */
|
/*! The argument must be an array. */
|
||||||
virtual const MacroValue *append(const MacroValue *array) const throw (TypeError);
|
virtual const MacroValue *append(const MacroValue *array) const throw (TypeError);
|
||||||
|
@ -217,6 +219,8 @@ public:
|
||||||
virtual string toString() const;
|
virtual string toString() const;
|
||||||
//! Returns itself
|
//! Returns itself
|
||||||
virtual const MacroValue *toArray() const;
|
virtual const MacroValue *toArray() const;
|
||||||
|
//! Gets length
|
||||||
|
virtual const MacroValue *length() const throw (TypeError);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
@ -329,4 +333,11 @@ ArrayMV<T>::toArray() const
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
const MacroValue *
|
||||||
|
ArrayMV<T>::length() const throw (TypeError)
|
||||||
|
{
|
||||||
|
return new IntMV(driver, values.size());
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue