diff --git a/source/ast/BinaryOpNode.cc b/source/ast/BinaryOpNode.cc index bf79f2d289d34049e90f33b5174f4a90287e6ff7..dfb707d1b8a1ee6bbc06512bb2b6f8f8406d00e1 100644 --- a/source/ast/BinaryOpNode.cc +++ b/source/ast/BinaryOpNode.cc @@ -58,7 +58,7 @@ Node* BinaryOpNode::evaluate() const String BinaryOpNode::to_s() const { - return "(" + left->to_s() + " " + token_type_to_s(op.get_type()) + " " + right->to_s() + ")"; + return "(" + left->to_s() + " " + op.get_lexeme() + " " + right->to_s() + ")"; } NodeValue BinaryOpNode::get_value() const diff --git a/source/ast/LiteralNode.cc b/source/ast/LiteralNode.cc index 94d2335bb8423e1ed0ba026c75a40dfd593f314e..a357243f21dbca0d086b274f826ceaef8ce3136d 100644 --- a/source/ast/LiteralNode.cc +++ b/source/ast/LiteralNode.cc @@ -13,6 +13,8 @@ Node* LiteralNode::evaluate() const String LiteralNode::to_s() const { + if (value.is_a<String>()) { return "\"" + value.get<String>() + "\""; } + if (value.is_a<char>()) { return "'" + String(1, value.get<char>()) + "'"; } return value.cast<String>(); } diff --git a/source/ast/NodeValue.cc b/source/ast/NodeValue.cc index 8206672355fadfae4dede3908b08a131b9e199ea..354f02835df452ad5a0bdf76ccc82a88823ed5bb 100644 --- a/source/ast/NodeValue.cc +++ b/source/ast/NodeValue.cc @@ -95,8 +95,13 @@ template <typename Op> NodeValue comparison(const NodeValue& lhs, const NodeValu NodeValue operator+(const NodeValue& lhs, const NodeValue& rhs) { - if (lhs.is_a<String>() && rhs.is_a<String>()) { return lhs.get<String>() + rhs.get<String>(); } + if ((lhs.is_a<String>() || lhs.is_a<char>()) && (rhs.is_a<String>() || rhs.is_a<char>())) + { + String left{lhs.is_a<String>() ? lhs.get<String>() : String(1, lhs.get<char>())}; + String right{rhs.is_a<String>() ? rhs.get<String>() : String(1, rhs.get<char>())}; + return left + right; + } return numeric_op(lhs, rhs, [](auto a, auto b) { return a + b; diff --git a/source/ast/UnaryOpNode.cc b/source/ast/UnaryOpNode.cc index 1eda4a94f0d5e332a9282f0346b981f6f47e8113..f275cd92e2793c2a490f0f4bf97d1d46242d1fd7 100644 --- a/source/ast/UnaryOpNode.cc +++ b/source/ast/UnaryOpNode.cc @@ -43,7 +43,7 @@ Node* UnaryOpNode::evaluate() const String UnaryOpNode::to_s() const { - return "(" + token_type_to_s(op.get_type()) + expr->to_s() + ")"; + return "(" + op.get_lexeme() + expr->to_s() + ")"; } NodeValue UnaryOpNode::get_value() const