Commit 8d9de2d5 authored by Houtan Bastani's avatar Houtan Bastani

macroprocessor: add @#echomacrovars command. #1564

parent 93a0351a
......@@ -205,3 +205,13 @@ MacroDriver::error(const Macro::parser::location_type &l, const MacroValue *valu
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
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
void set_variable(const string &name, const MacroValue *value);
......
/*
* Copyright (C) 2008-2016 Dynare Team
* Copyright (C) 2008-2017 Dynare Team
*
* This file is part of Dynare.
*
......@@ -236,6 +236,8 @@ CONT \\\\
<STMT>line { return token::LINE; }
<STMT>define { return token::DEFINE; }
<STMT>echomacrovars{SPC}*{EOL} { driver.printvars(*yylloc); BEGIN(INITIAL); }
<STMT>for { reading_for_statement = true; return token::FOR; }
<STMT>endfor { driver.error(*yylloc, "@#endfor is not matched by a @#for statement"); }
......
/*
* Copyright (C) 2008-2014 Dynare Team
* Copyright (C) 2008-2017 Dynare Team
*
* This file is part of Dynare.
*
......@@ -280,6 +280,12 @@ IntMV::toString() const
return ss.str();
}
string
IntMV::print() const
{
return toString();
}
const MacroValue *
IntMV::toArray() const
{
......@@ -398,6 +404,12 @@ StringMV::toString() const
return value;
}
string
StringMV::print() const
{
return toString();
}
const MacroValue *
StringMV::toArray() const
{
......
......@@ -91,6 +91,8 @@ public:
virtual const MacroValue *operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError);
//! Converts value to string
virtual string toString() const = 0;
//! Converts value to be printed
virtual string print() const = 0;
//! Converts value to array form
virtual const MacroValue *toArray() const = 0;
//! Gets length
......@@ -147,6 +149,7 @@ public:
//! Computes logical negation
virtual const MacroValue *operator!() const throw (TypeError);
virtual string toString() const;
virtual string print() const;
//! Converts value to array form
/*! Returns an integer array containing a single value */
virtual const MacroValue *toArray() const;
......@@ -187,6 +190,7 @@ public:
virtual const MacroValue *operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError);
//! Returns underlying string value
virtual string toString() const;
virtual string print() const;
//! Converts value to array form
/*! Returns a string array containing a single value */
virtual const MacroValue *toArray() const;
......@@ -226,6 +230,7 @@ public:
virtual const MacroValue *operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsError);
//! Returns a string containing the concatenation of string representations of elements
virtual string toString() const;
virtual string print() const;
//! Returns itself
virtual const MacroValue *toArray() const;
//! Gets length
......@@ -335,6 +340,23 @@ ArrayMV<T>::toString() const
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>
const MacroValue *
ArrayMV<T>::toArray() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment