diff --git a/Nodes.cpp b/Nodes.cpp index 2ebf93d..9cc0b63 100644 --- a/Nodes.cpp +++ b/Nodes.cpp @@ -161,9 +161,19 @@ void Assignment::emit(std::ostream &stream, int indent) { } void Print::emit(std::ostream &stream, int indent) { - stream << "std::cout << ("; + bool simpleExpression = (dynamic_cast(expression.get()) != nullptr); + + stream << "std::cout << "; + if (!simpleExpression) { + stream << '('; + } + expression->emit(stream); - stream << ") << std::endl"; + + if (!simpleExpression) { + stream << ')'; + } + stream << " << std::endl"; } void Input::emit(std::ostream &stream, int indent) {