From 8b195653729025f1dac04b198c4d7b030e7f6410 Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Thu, 27 Jun 2019 11:48:03 +0200 Subject: [PATCH] macro processor: prefer superfluous parenthesis when printing than printing with incorrect precedence --- src/macro/Expressions.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/macro/Expressions.cc b/src/macro/Expressions.cc index 7b42ac56..a722a862 100644 --- a/src/macro/Expressions.cc +++ b/src/macro/Expressions.cc @@ -1102,7 +1102,7 @@ UnaryOp::to_string() const noexcept string BinaryOp::to_string() const noexcept { - string retval = arg1->to_string(); + string retval = "(" + arg1->to_string(); switch(op_code) { case codes::BinaryOp::plus: @@ -1158,7 +1158,7 @@ BinaryOp::to_string() const noexcept case codes::BinaryOp::mod: return "mod(" + retval + ", " + arg2->to_string() + ")"; } - return retval + arg2->to_string(); + return retval + arg2->to_string() + ")"; } string @@ -1367,6 +1367,7 @@ BinaryOp::print(ostream &output, bool matlab_output) const noexcept return; } + output << "("; arg1->print(output, matlab_output); switch(op_code) { @@ -1421,6 +1422,7 @@ BinaryOp::print(ostream &output, bool matlab_output) const noexcept exit(EXIT_FAILURE); } arg2->print(output, matlab_output); + output << ")"; } void -- GitLab