- if (ctx->conditional() == nullptr && ctx->loop() == nullptr)\r
- o << ";";\r
-}\r
-void toc(std::ostream & o, TocParser::IfCondContext * ctx) {\r
- o << "if (";\r
- toc(o, ctx->expr());\r
- o << ")\n{\n";\r
- toc(o, ctx->body());\r
- o << "}\n";\r
-}\r
-void toc(std::ostream & o, TocParser::WhileLoopContext * ctx) {\r
- o << "while (";\r
- toc(o, ctx->expr());\r
- o << ")\n{\n";\r
- toc(o, ctx->body());\r
- o << "}\n";\r
-}\r
-void toc(std::ostream & o, TocParser::AssignmentContext * ctx) {\r
- toc(o, ctx->identifier());\r
- o << " = ";\r
- toc(o, ctx->expr());\r
-}\r
-void toc(std::ostream & o, TocParser::ReturnStmtContext * ctx) {\r
- o << "return ";\r
- toc(o, ctx->expr());\r
-}\r
-void toc(std::ostream & o, TocParser::ExprContext * ctx) {\r
- /**/ if (ctx->funcCall() != nullptr) toc(o, ctx->funcCall());\r
- else if (ctx->identifier() != nullptr) toc(o, ctx->identifier());\r
- else if (ctx->literal() != nullptr) toc(o, ctx->literal());\r
- else if (ctx->subscript() != nullptr) toc(o, ctx->subscript());\r
- else if (ctx->memberAccess() != nullptr) toc(o, ctx->memberAccess());\r
- else if (ctx->parenExpr() != nullptr) toc(o, ctx->parenExpr());\r
- else if (ctx->operatorExpr() != nullptr) toc(o, ctx->operatorExpr()->binaryOperator());\r
-}\r
-void toc(std::ostream & o, TocParser::NonOpExprContext * ctx) {\r
- /**/ if (ctx->funcCall() != nullptr) toc(o, ctx->funcCall());\r
- else if (ctx->identifier() != nullptr) toc(o, ctx->identifier());\r
- else if (ctx->literal() != nullptr) toc(o, ctx->literal());\r
- else if (ctx->subscript() != nullptr) toc(o, ctx->subscript());\r
- else if (ctx->memberAccess() != nullptr) toc(o, ctx->memberAccess());\r
- else if (ctx->parenExpr() != nullptr) toc(o, ctx->parenExpr());\r
-}\r
-void toc(std::ostream & o, TocParser::NonSubscriptExprContext * ctx) {\r
- /**/ if (ctx->funcCall() != nullptr) toc(o, ctx->funcCall());\r
- else if (ctx->identifier() != nullptr) toc(o, ctx->identifier());\r
- else if (ctx->memberAccess() != nullptr) toc(o, ctx->memberAccess());\r
- else if (ctx->parenExpr() != nullptr) toc(o, ctx->parenExpr());\r
-}\r
-void toc(std::ostream & o, TocParser::FuncCallContext * ctx) {\r
- o\r
- << ctx->funcName()->getText()\r
- << "(";\r
- for (int i = 0; i < ctx->expr().size(); i++) {\r
- if (i != 0) o << ", ";\r
- toc(o, ctx->expr(i));\r
+ return out;\r
+}\r
+std::ostream & operator<< (std::ostream & out, const BinaryOperatorExpr & o) {\r
+ out << *o.lexpr << " " << BinaryOperatorTypeStrings[(int)o.type] << " " << *o.rexpr;\r
+\r
+ return out;\r
+}\r
+std::ostream & operator<< (std::ostream & out, const TernaryOperatorExpr & o) {\r
+ out << *o.lexpr << " ? " << *o.rexprTrue << " : " << *o.rexprFalse;\r
+\r
+ return out;\r
+}\r
+std::ostream & operator<< (std::ostream & out, const Expr & e) {\r
+ if (e.parenthesized)\r
+ out << "(";\r
+\r
+ switch (e.type) {\r
+ case ExprType::Func:\r
+ out << e._func.functionName << "(" << e._func.arguments << ")"; break;\r
+ case ExprType::Lit:\r
+ /**/ if (e._lit.type == LitType::Int) out << e._lit._int;\r
+ else if (e._lit.type == LitType::Decimal) out << e._lit._decimal;\r
+ else if (e._lit.type == LitType::String) out << e._lit._string;\r
+ else if (e._lit.type == LitType::Bool) out << e._lit._bool;\r
+ break;\r
+ case ExprType::Identifier:\r
+ out << e._identifier.name; break;\r
+ case ExprType::Brackets:\r
+ out << *e._brackets.lexpr << "[" << *e._brackets.rexpr << "]"; break;\r
+ case ExprType::Dot:\r
+ out << *e._dot.expr << "." << e._dot.ident.name; break;\r
+ case ExprType::UnaryOperator:\r
+ out << e._unaryOperator; break;\r
+ case ExprType::BinaryOperator:\r
+ out << e._binaryOperator; break;\r
+ case ExprType::TernaryOperator:\r
+ out << e._ternaryOperator; break;\r