macroprocessor: add @#echomacrovars command. #1564
parent
68627a0465
commit
f836aa92c5
|
@ -205,3 +205,13 @@ MacroDriver::error(const Macro::parser::location_type &l, const MacroValue *valu
|
||||||
|
|
||||||
error(l, sval->value);
|
error(l, sval->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
MacroDriver::printvars(const Macro::parser::location_type &l) const
|
||||||
|
{
|
||||||
|
cout << "Macroprocessor: Printing macro variable values at line " << l << endl;
|
||||||
|
for (map<string, const MacroValue *>::const_iterator it = env.begin();
|
||||||
|
it != env.end(); it++)
|
||||||
|
cout << "|- " << it->first << " = " << it->second->print() << endl;
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
|
@ -197,6 +197,9 @@ public:
|
||||||
//! Error handler
|
//! Error handler
|
||||||
void error(const Macro::parser::location_type &l, const string &m) const;
|
void error(const Macro::parser::location_type &l, const string &m) const;
|
||||||
|
|
||||||
|
//! Print variables
|
||||||
|
void printvars(const Macro::parser::location_type &l) const;
|
||||||
|
|
||||||
//! Set a variable
|
//! Set a variable
|
||||||
void set_variable(const string &name, const MacroValue *value);
|
void set_variable(const string &name, const MacroValue *value);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2016 Dynare Team
|
* Copyright (C) 2008-2017 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -236,6 +236,8 @@ CONT \\\\
|
||||||
<STMT>line { return token::LINE; }
|
<STMT>line { return token::LINE; }
|
||||||
<STMT>define { return token::DEFINE; }
|
<STMT>define { return token::DEFINE; }
|
||||||
|
|
||||||
|
<STMT>echomacrovars{SPC}*{EOL} { driver.printvars(*yylloc); BEGIN(INITIAL); }
|
||||||
|
|
||||||
<STMT>for { reading_for_statement = true; return token::FOR; }
|
<STMT>for { reading_for_statement = true; return token::FOR; }
|
||||||
<STMT>endfor { driver.error(*yylloc, "@#endfor is not matched by a @#for statement"); }
|
<STMT>endfor { driver.error(*yylloc, "@#endfor is not matched by a @#for statement"); }
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2008-2014 Dynare Team
|
* Copyright (C) 2008-2017 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -280,6 +280,12 @@ IntMV::toString() const
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
IntMV::print() const
|
||||||
|
{
|
||||||
|
return toString();
|
||||||
|
}
|
||||||
|
|
||||||
const MacroValue *
|
const MacroValue *
|
||||||
IntMV::toArray() const
|
IntMV::toArray() const
|
||||||
{
|
{
|
||||||
|
@ -398,6 +404,12 @@ StringMV::toString() const
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string
|
||||||
|
StringMV::print() const
|
||||||
|
{
|
||||||
|
return toString();
|
||||||
|
}
|
||||||
|
|
||||||
const MacroValue *
|
const MacroValue *
|
||||||
StringMV::toArray() const
|
StringMV::toArray() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -91,6 +91,8 @@ public:
|
||||||
virtual const MacroValue *operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError);
|
virtual const MacroValue *operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError);
|
||||||
//! Converts value to string
|
//! Converts value to string
|
||||||
virtual string toString() const = 0;
|
virtual string toString() const = 0;
|
||||||
|
//! Converts value to be printed
|
||||||
|
virtual string print() 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
|
//! Gets length
|
||||||
|
@ -147,6 +149,7 @@ public:
|
||||||
//! Computes logical negation
|
//! Computes logical negation
|
||||||
virtual const MacroValue *operator!() const throw (TypeError);
|
virtual const MacroValue *operator!() const throw (TypeError);
|
||||||
virtual string toString() const;
|
virtual string toString() const;
|
||||||
|
virtual string print() const;
|
||||||
//! Converts value to array form
|
//! Converts value to array form
|
||||||
/*! Returns an integer array containing a single value */
|
/*! Returns an integer array containing a single value */
|
||||||
virtual const MacroValue *toArray() const;
|
virtual const MacroValue *toArray() const;
|
||||||
|
@ -187,6 +190,7 @@ public:
|
||||||
virtual const MacroValue *operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError);
|
virtual const MacroValue *operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError);
|
||||||
//! Returns underlying string value
|
//! Returns underlying string value
|
||||||
virtual string toString() const;
|
virtual string toString() const;
|
||||||
|
virtual string print() const;
|
||||||
//! Converts value to array form
|
//! Converts value to array form
|
||||||
/*! Returns a string array containing a single value */
|
/*! Returns a string array containing a single value */
|
||||||
virtual const MacroValue *toArray() const;
|
virtual const MacroValue *toArray() const;
|
||||||
|
@ -226,6 +230,7 @@ public:
|
||||||
virtual const MacroValue *operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError);
|
virtual const MacroValue *operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError);
|
||||||
//! Returns a string containing the concatenation of string representations of elements
|
//! Returns a string containing the concatenation of string representations of elements
|
||||||
virtual string toString() const;
|
virtual string toString() const;
|
||||||
|
virtual string print() const;
|
||||||
//! Returns itself
|
//! Returns itself
|
||||||
virtual const MacroValue *toArray() const;
|
virtual const MacroValue *toArray() const;
|
||||||
//! Gets length
|
//! Gets length
|
||||||
|
@ -335,6 +340,23 @@ ArrayMV<T>::toString() const
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
string
|
||||||
|
ArrayMV<T>::print() const
|
||||||
|
{
|
||||||
|
ostringstream ss;
|
||||||
|
ss << "[";
|
||||||
|
for (typename vector<T>::const_iterator it = values.begin();
|
||||||
|
it != values.end(); it++)
|
||||||
|
{
|
||||||
|
if (it != values.begin())
|
||||||
|
ss << ", ";
|
||||||
|
ss << *it;
|
||||||
|
}
|
||||||
|
ss << "]";
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
const MacroValue *
|
const MacroValue *
|
||||||
ArrayMV<T>::toArray() const
|
ArrayMV<T>::toArray() const
|
||||||
|
|
Loading…
Reference in New Issue